Create Insight
Create a new insight to save a chart, analysis, or visualization in PostHog. Insights can contain trends, funnels, retention analysis, path analysis, and more.
Endpoint
POST /api/projects/:project_id/insights/
Path Parameters
The ID of the project to create the insight in
Request Body
Name of the insight. If not provided, PostHog will generate a derived name from the query.
Optional description explaining what this insight shows
The query definition for this insight. The kind field determines the query type:
InsightVizNode — Product analytics (trends, funnels, retention, paths, stickiness, lifecycle)
DataVisualizationNode — SQL insights using HogQL
DataTableNode — Raw data tables
HogQuery — Hog language queries
Example for a trends query:{
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "$pageview",
"name": "$pageview"
}
],
"dateRange": {
"date_from": "-7d"
}
}
}
Legacy filter format (deprecated). Use query instead for new insights.
Array of dashboard IDs to add this insight to
Whether to save this insight. Set to false for temporary/unsaved insights.
Whether to mark this insight as favorited
Array of tag names to apply to this insight
Response Fields
Unique identifier for the insight
Short, human-readable ID for the insight (used in URLs)
Auto-generated name if no explicit name was provided
The query definition for this insight
Query results (if calculated)
User who created the insight
ISO 8601 timestamp of creation
ISO 8601 timestamp of when results were last calculated
Whether the results are from cache
Examples
Create Trends Insight
Create an insight showing pageview trends over the last 7 days:
curl -X POST https://app.posthog.com/api/projects/12345/insights/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Pageviews Last 7 Days",
"description": "Daily pageview count for the past week",
"query": {
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "$pageview",
"name": "$pageview"
}
],
"dateRange": {
"date_from": "-7d"
},
"interval": "day"
}
},
"saved": true
}'
Create Funnel Insight
Create a conversion funnel insight:
curl -X POST https://app.posthog.com/api/projects/12345/insights/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Signup Funnel",
"description": "Conversion from signup to first action",
"query": {
"kind": "InsightVizNode",
"source": {
"kind": "FunnelsQuery",
"series": [
{
"kind": "EventsNode",
"event": "signup_started",
"name": "Signup Started"
},
{
"kind": "EventsNode",
"event": "signup_completed",
"name": "Signup Completed"
},
{
"kind": "EventsNode",
"event": "first_action",
"name": "First Action"
}
],
"dateRange": {
"date_from": "-30d"
},
"funnelWindowInterval": 7,
"funnelWindowIntervalUnit": "day"
}
}
}'
Create SQL Insight
Create a SQL-based insight using HogQL:
curl -X POST https://app.posthog.com/api/projects/12345/insights/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Top Events by Count",
"query": {
"kind": "DataVisualizationNode",
"source": {
"kind": "HogQLQuery",
"query": "SELECT event, count() as count FROM events WHERE timestamp > now() - INTERVAL 7 DAY GROUP BY event ORDER BY count DESC LIMIT 10"
},
"display": {
"type": "table"
}
}
}'
Add to Dashboard
Create an insight and add it to a dashboard:
curl -X POST https://app.posthog.com/api/projects/12345/insights/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "User Signups",
"query": {
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "signup_completed"
}
],
"dateRange": {
"date_from": "-30d"
}
}
},
"dashboards": [456, 789]
}'
Response
{
"id": 9876,
"short_id": "abc123",
"name": "Pageviews Last 7 Days",
"derived_name": "$pageview count",
"description": "Daily pageview count for the past week",
"query": {
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "$pageview",
"name": "$pageview"
}
],
"dateRange": {
"date_from": "-7d"
},
"interval": "day"
}
},
"result": null,
"created_by": {
"id": 123,
"uuid": "01234567-89ab-cdef-0123-456789abcdef",
"distinct_id": "[email protected]",
"first_name": "Jane",
"email": "[email protected]"
},
"created_at": "2024-01-15T10:30:00Z",
"last_modified_at": "2024-01-15T10:30:00Z",
"last_refresh": null,
"is_cached": false,
"saved": true,
"favorited": false,
"dashboards": [],
"tags": []
}
Error Responses
Invalid query structure or missing required fields{
"detail": "Query must be a valid JSON object"
}
Invalid or missing API key
Insufficient permissions to create insights
Notes
- Insights are not automatically calculated on creation; results are calculated on first view or when explicitly refreshed
- Use the
query field for all new insights (the filters field is deprecated)
- Insights can be added to multiple dashboards
- Set
saved: false to create temporary/exploratory insights that don’t clutter your saved insights
- Query results are cached for performance; use the
refresh parameter when retrieving to force recalculation