Query Insights
Execute insight queries and retrieve results without creating a saved insight. This endpoint is useful for exploratory analysis, building custom dashboards, or programmatically analyzing your PostHog data.Endpoint
Path Parameters
integer
required
The ID of the project to query
Query Parameters
string
How to handle result calculation:
force_cache- Return cached data only (fastest, may return cache miss)blocking- Calculate synchronously if cache is staleasync- Kick off background calculation if needed, return immediatelylazy_async- Background calculation for somewhat stale cacheforce_blocking- Always calculate synchronouslyforce_async- Always calculate in background
force_cachestring
Optional client-provided query ID for tracking and cancellation
Request Body
The request body should contain a query object matching one of the supported query types.Trends Query
string
required
Set to
TrendsQuery for trends analysisarray
required
Array of event or action nodes to analyze
object
Date range for the analysis (e.g.,
{"date_from": "-7d"})string
Time interval:
hour, day, week, monthobject
Break down results by properties
array
Filter events by properties
Funnels Query
string
required
Set to
FunnelsQuery for conversion funnel analysisarray
required
Ordered array of funnel steps (events or actions)
number
Time window for conversion (e.g., 7)
string
Unit for funnel window:
hour, day, week, monthHogQL Query
string
required
Set to
HogQLQuery for SQL queriesstring
required
HogQL (SQL-like) query string
Response Fields
any
Query results (format depends on query type)
boolean
Whether there are more results available (for paginated queries)
array
Column definitions (for table results)
array
Data types for each column
string
The HogQL query that was executed (for debugging)
object
string
ISO 8601 timestamp of when results were calculated
boolean
Whether results came from cache
string
Timezone used for date calculations
array
Performance timing information
Examples
Trends Query
Query pageview trends over the last 7 days:Funnel Query
Analyze conversion through a signup funnel:HogQL Query
Run a SQL query using HogQL:Query with Breakdown
Analyze events broken down by a property:Response Examples
Trends Query Response
Funnel Query Response
HogQL Query Response
Error Responses
error
Invalid query structure
error
Invalid or missing API key
error
Insufficient permissions to query data
error
Rate limit exceeded
error
Query execution error
Notes
- Queries are executed against your ClickHouse analytics database
- Results are cached for performance; use
refreshparameter to control caching behavior - Use
force_cachefor fastest responses (may return cache miss if no cached results) - Use
blockingto ensure fresh results while maintaining synchronous response - Use
asyncfor expensive queries to avoid timeouts - Query execution is subject to rate limits
- HogQL queries must be read-only (SELECT statements only)
- Results are automatically formatted based on query type
- Aggregate queries (count, sum, etc.) return numeric results
- Time-series queries return arrays of data points