Insights API
List, read, create and update saved insights through the API, and fetch their results.
An insight is a saved chart or table: a trend, funnel, retention table, SQL query and so on. The insights API manages saved insights and returns their latest results.
To calculate something without saving an insight, use the query API.
Reading needs a personal API key with insight:read; creating and changing insights needs insight:write.
List insights
GET /api/projects/<project ID>/insights/| Parameter | Description |
|---|---|
short_id | The insight with this short ID |
search | Insights whose name, description or tags contain this text |
saved | true for saved insights only |
favorited | Any value to return only favourited insights |
insight | One type only: TRENDS, FUNNELS, RETENTION, PATHS, STICKINESS, LIFECYCLE or SQL |
basic | true to return names and settings without results, which is faster |
limit, offset | Paging, see pagination |
curl "https://app.myjourneyanalytics.com/api/projects/12345/insights/?saved=true&basic=true" \
-H "Authorization: Bearer <personal API key>"Get an insight and its results
Every insight has a numeric id and a short_id. The short ID is the code in the insight's address in the app: in https://app.myjourneyanalytics.com/project/12345/insights/aB3dE9xY it is aB3dE9xY.
curl "https://app.myjourneyanalytics.com/api/projects/12345/insights/?short_id=aB3dE9xY&refresh=blocking" \
-H "Authorization: Bearer <personal API key>"Or by numeric ID:
GET /api/projects/<project ID>/insights/<insight ID>/?refresh=blockingThe response includes the insight's query, its result and last_refresh, the time the result was calculated.
The refresh parameter decides whether results are recalculated:
| Value | Behaviour |
|---|---|
force_cache | Return cached results only, never calculate. Fastest |
blocking | Use recent cached results if there are any; otherwise calculate and wait |
force_blocking | Always recalculate and wait |
async | Use recent cached results, or start calculating in the background and return straight away |
force_async | Always start a fresh calculation in the background |
With async and force_async, check query_status in the response, then request the insight again once the calculation is complete.
Create an insight
An insight is defined by a query. This one is a daily trend of pageviews over the last 7 days:
curl -X POST https://app.myjourneyanalytics.com/api/projects/12345/insights/ \
-H "Authorization: Bearer <personal API key>" \
-H "Content-Type: application/json" \
-d '{
"name": "Pageviews, last 7 days",
"saved": true,
"query": {
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [{ "kind": "EventsNode", "event": "$pageview", "math": "total" }],
"dateRange": { "date_from": "-7d" },
"interval": "day"
}
}
}'The quickest way to get the query for anything more complex is to build the insight in the app, then read it back with the API and copy its query.
Older integrations may send a filters object instead of a query. That is no longer accepted: send a query.
Update an insight
Send only what you want to change:
curl -X PATCH https://app.myjourneyanalytics.com/api/projects/12345/insights/<insight ID>/ \
-H "Authorization: Bearer <personal API key>" \
-H "Content-Type: application/json" \
-d '{ "name": "Pageviews (all sites), last 7 days" }'Delete an insight
Insights are not deleted with DELETE, which returns 405. Mark them deleted instead:
curl -X PATCH https://app.myjourneyanalytics.com/api/projects/12345/insights/<insight ID>/ \
-H "Authorization: Bearer <personal API key>" \
-H "Content-Type: application/json" \
-d '{ "deleted": true }'Can't find what you need? Contact support