Query

For instructions on how to authenticate to use this endpoint, see API overview.

Create query

Required API key scopes

query:read

Path parameters

  • project_id
    string

    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
RESPONSE
{}

Retrieve query

(Experimental)

Required API key scopes

query:read

Path parameters

  • id
    string
  • project_id
    string

    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

  • id
    string
  • project_id
    string

    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_id
    string

    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/

Response

Status 200 No response body

Questions?

Was this page useful?