Skip to main content

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 stale
  • async - Kick off background calculation if needed, return immediately
  • lazy_async - Background calculation for somewhat stale cache
  • force_blocking - Always calculate synchronously
  • force_async - Always calculate in background
Default: force_cache
string
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.
string
required
Set to TrendsQuery for trends analysis
array
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, month
object
Break down results by properties
array
Filter events by properties

Funnels Query

string
required
Set to FunnelsQuery for conversion funnel analysis
array
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, month

HogQL Query

string
required
Set to HogQLQuery for SQL queries
string
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
Query execution status and metadata
string
Query ID
boolean
Whether query execution is complete
boolean
Whether an error occurred
string
Error message if query failed
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

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

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 refresh parameter to control caching behavior
  • Use force_cache for fastest responses (may return cache miss if no cached results)
  • Use blocking to ensure fresh results while maintaining synchronous response
  • Use async for 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