Query
For instructions on how to authenticate to use this endpoint, see API overview.
Endpoints
Create query
Required API key scopes
query:read
Path parameters
- project_idstring
Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.
Request parameters
- async
(Experimental) Whether to run the query asynchronously. Defaults to False. If True, the
id
of the query can be used to check the status and to cancel it. - client_query_id
Client provided query ID. Can be used to retrieve the status or cancel the query.
- query
Submit a JSON string representing a query for PostHog data analysis, for example a HogQL query.
Example payload:
{"query": {"kind": "HogQLQuery", "query": "select * from events limit 100"}}
For more details on HogQL queries, see the PostHog HogQL documentation.
- refresh
Response
Request
POST
/api /projects /:project_id /query
export POSTHOG_PERSONAL_API_KEY=[your personal api key]curl-H 'Content-Type: application/json'\-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \https://app.posthog.com/api/projects/:project_id/query/\-d query=undefined
Response
Status 200
{}
Retrieve query
(Experimental)
Required API key scopes
query:read
Path parameters
- idstring
- project_idstring
Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.
Request
GET
/api /projects /:project_id /query /:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]curl \-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \https://app.posthog.com/api/projects/:project_id/query/:id/
Response
Status 200 Query status
Delete query
(Experimental)
Required API key scopes
query:read
Path parameters
- idstring
- project_idstring
Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.
Request
DELETE
/api /projects /:project_id /query /:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]curl -X DELETE \-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \https://app.posthog.com/api/projects/:project_id/query/:id/
Response
Status 204 Query cancelled
Retrieve query draft sql
Path parameters
- project_idstring
Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.
Request
GET
/api /projects /:project_id /query /draft_sql
export POSTHOG_PERSONAL_API_KEY=[your personal api key]curl \-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \https://app.posthog.com/api/projects/:project_id/query/draft_sql/