This is the main endpoint for querying data from PostHog. It is used for many kinds of queries including TrendsQuery
, FunnelsQuery
, ActorsQuery
, EventsQuery
, and more.
The most useful for you is likely HogQLQuery
. This enables you to query PostHog using HogQL. For example, to get events where the $current_url
contains blog:
curl \-H 'Content-Type: application/json' \-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \<ph_app_host>/api/projects/:project_id/query/ \-d '{"query": {"kind": "HogQLQuery","query": "select properties.$current_url from events where properties.$current_url like '\''%/blog%'\'' limit 100"}}'
It is also useful for querying non-event data like persons, data warehouse, session replay metadata, and more. For example, to get a list of all people with the email
property:
curl \-H 'Content-Type: application/json' \-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \<ph_app_host>/api/projects/:project_id/query/ \-d '{"query": {"kind": "HogQLQuery","query": "select properties.email from persons where properties.email is not null"}}'
Note: This endpoint is limited to 10,000 rows at 120 requests per hour. If you need more, use batch exports.
To learn more, read the query endpoint code on GitHub or search for query
requests in your browser's network tab in PostHog.