Run query with the PostHog API

Runs an ad hoc analytics query and returns its results, up to 100 rows unless the SQL sets a LIMIT. It is not an export: PostHog refuses OFFSET, limits each project to 3 queries at a time and debits every query from an hourly read budget.

Identifier
posthog_run_query

The request

POST https://connect.reportei.com/api/tools/posthog_run_query/execute
Authorization: Bearer <merchant token>
x-customer-token: <customer token>
Content-Type: application/json
Accept: application/json

{
  "customer_toolkit": "<connection UUID>",
  "arguments": {
    "project_id": "<project_id>",
    "query": {}
  }
}

Your system sends your customer's connection id and the tool arguments. The headers are the same as the rest of the Connect API: your product's token and your customer's token.

Parameters

ParameterTypeRequiredDescription
project_idstringYesId of the project: the project_id of a team in List organizations, or the number after /project/ in the URL of PostHog.
queryobjectYesThe query. kind HogQLQuery runs the SQL of query over tables such as events, persons and sessions. The insight kinds, such as TrendsQuery, FunnelsQuery and RetentionQuery, take their own fields here instead, for example series and dateRange.
namestringNoShort name of the query, shown in the query log of the project.
refreshstringNoblocking, the default, calculates now unless fresh results are cached. force_blocking always calculates, and force_cache only returns cached results.Values: blocking, force_blocking, force_cache

Supported connections

Your customer connects their PostHog account once, with one of the modes below. The same connection serves every tool of the toolkit.

API key

Your customer pastes the app's key on a Connect screen, or your system sends the key with POST /api/customer-toolkits, with no screen.

When connecting, your customer also enters {region}: the address of their account on the app's API.

The response

On success, Connect preserves the app's response status and body. HTTP errors returned by the app use the {error, api_error} envelope; authentication or validation can fail before execution. The X-Toolkit-Execution-Id header identifies the recorded execution, available at GET /api/tools/executions/{uuid}.

Ready for AI agents

This tool's input is a JSON Schema, available at GET /api/tools/posthog_run_query. It becomes your agent's tool definition with no conversion.

See Connect applied to your product.

Try it for 15 days with no card, or walk our team through your use case.