Query

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

Create query

This is the main endpoint for querying data from PostHog. You can find all the details on what it does and how you can use it in our API queries doc.

If you don't want to read that, here's an example of how to use it to get events where the $current_url contains blog using the HogQLQuery query type and SQL.

Tip: Always include a descriptive name parameter in your queries. This makes them easier to identify and analyze in the query_log table.

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"
},
"name": "get 100 blog urls"
}'

Again, more details about this endpoint are available in our API queries doc.

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

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

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": null,
"results": null,
"start_time": null,
"task_id": null,
"team_id": 0
}
}

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

Response

Status 204 Query cancelled

Retrieve query log

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

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.

Response

Status 200

Create query check auth for async

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

Response

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

Response

Status 200 No response body

Create query upgrade

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

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

Response

Status 200
RESPONSE
{
"query": {
"custom_name": null,
"event": null,
"fixedProperties": null,
"kind": "EventsNode",
"limit": null,
"math": null,
"math_group_type_index": null,
"math_hogql": null,
"math_multiplier": null,
"math_property": null,
"math_property_revenue_currency": null,
"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.