Query

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

Endpoints

POST
GET
DELETE
GET
POST
GET
POST

Create query create

Required API key scopes

query:read

Path parameters

  • project_id
    string

Request parameters

  • async
    boolean
  • client_query_id
    string
  • filters_override
  • name
    string
  • query
  • refresh
    Default: blocking
  • variables_override
    object

Response


Example 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" \
<ph_app_host>/api/projects/:project_id/query/\
-d query=undefined

Example response

Status 200
RESPONSE
{}

Retrieve query retrieve

(Experimental)

Required API key scopes

query:read

Path parameters

  • id
    string
  • project_id
    string

Response


Example 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" \
<ph_app_host>/api/projects/:project_id/query/:id/

Example response

Status 200
RESPONSE
{
"query_status": {
"complete": false,
"dashboard_id": null,
"end_time": null,
"error": false,
"error_message": null,
"expiration_time": null,
"id": "string",
"insight_id": null,
"labels": null,
"pickup_time": null,
"query_async": true,
"query_progress": {
"active_cpu_time": 0,
"bytes_read": 0,
"estimated_rows_total": 0,
"rows_read": 0,
"time_elapsed": 0
},
"results": null,
"start_time": null,
"task_id": null,
"team_id": 0
}
}

Delete query destroy

(Experimental)

Required API key scopes

query:read

Path parameters

  • id
    string
  • project_id
    string

Example 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" \
<ph_app_host>/api/projects/:project_id/query/:id/

Example response

Status 204 Query cancelled

Retrieve query log retrieve

Get query log details from query_log_archive table for a specific query_id, the query must have been issued in last 24 hours.

Path parameters

  • id
    string
  • project_id
    string

Example request

GET /api/projects/:project_id/query/:id/log
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/query/:id/log/

Example response

Status 200

Create query check auth for async create

Path parameters

  • project_id
    string

Example request

POST /api/projects/:project_id/query/check_auth_for_async
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/query/check_auth_for_async/

Example response

Status 200 No response body

Retrieve query draft sql retrieve

Path parameters

  • project_id
    string

Example 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" \
<ph_app_host>/api/projects/:project_id/query/draft_sql/

Example response

Status 200 No response body

Create query upgrade create

Upgrades a query without executing it. Returns a query with all nodes migrated to the latest version.

Path parameters

  • project_id
    string

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/query/upgrade
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/query/upgrade/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"query": {
"custom_name": null,
"event": null,
"fixedProperties": null,
"kind": "EventsNode",
"limit": null,
"math": null,
"math_group_type_index": 0,
"math_hogql": null,
"math_multiplier": null,
"math_property": null,
"math_property_revenue_currency": {
"property": null,
"static": "AED"
},
"math_property_type": null,
"name": null,
"optionalInFunnel": null,
"orderBy": null,
"properties": null,
"response": null,
"version": null
}
}

Community questions

Questions about this page? or post a community question.