Query

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

Create query

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/.

Query Parameters

  • async
    boolean

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

    Client provided query ID. Can be used to retrieve the status or cancel the query.

  • query
    string

    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.

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/

Response

Status 200 Query results

Retrieve query

(Experimental)

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)

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 No response body

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?