External Data

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

Endpoints

POST
POST
POST
POST
GET
GET

Create external data sources preview resource

Read a bounded sample of rows for one resource of a Custom REST source.

Lets a manifest author verify data_selector, primary_key, and the incremental cursor_path against live data before creating the source. Only source_type: "Custom" is supported — other source types return 400. The read is bounded (single page per resource, capped row count, short timeouts, no redirects). Manifest, validation, and SSRF problems return 400; a live fetch failure returns 200 with error set and empty rows.

Required API key scopes

external_data_source:write

Request parameters

  • source_type
  • payload
    object
  • resource_name
    string
  • limit
    integer
    Default: 10

Response


Example request

POST /api/projects/:project_id/external_data_sources/preview_resource
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/external_data_sources/preview_resource/\
-d source_type=undefined,\
-d resource_name="string"

Example response

Status 200
RESPONSE
{
"rows": [
{}
],
"row_count": 0,
"columns": [
{
"name": "string",
"type": "string"
}
],
"error": "string"
}

Create external data sources setup

One-shot data warehouse source setup.

Validate credentials, discover available tables, enable them all with sensible sync defaults (incremental where supported, else append, else full refresh), and create the source in a single call — the caller never has to assemble a schemas array. For sources that support webhooks (e.g. Stripe), a webhook is auto-registered after creation: on success webhook-capable tables switch to real-time webhook sync (unlocking webhook-only tables); on failure the polling defaults stay in place. For fine-grained table/sync control, use the lower-level database_schema + create flow instead.

Required API key scopes

external_data_source:write

Request parameters

  • source_type
  • payload
    object
  • prefix
    stringnull
  • description
    stringnull
  • direct_query_enabled
    boolean
    Default: true

Response


Example request

POST /api/projects/:project_id/external_data_sources/setup
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/external_data_sources/setup/\
-d source_type=undefined

Example response

Status 201
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"webhook": {
"success": true,
"webhook_url": "string",
"error": "string",
"pending_inputs": [
"string"
]
}
}

Create external data sources source prefix

Create, Read, Update and Delete External data Sources.

Required API key scopes

external_data_source:write

Request parameters

  • created_via
  • client_secret
    string
  • account_id
    string
  • prefix
    stringnull
  • description
    stringnull
  • direct_query_enabled
    boolean
  • job_inputs

Example request

POST /api/projects/:project_id/external_data_sources/source_prefix
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/external_data_sources/source_prefix/\
-d client_secret="string",\
-d account_id="string"

Example response

Status 200 No response body

Create external data sources store credentials

Validate and store credentials for a data warehouse source without creating the source.

Backs the source connect page: the user enters credentials directly in PostHog, they are checked against a live connection, then stashed encrypted in a temporary store. The returned credential id can be passed to setup as {'credential_id': <id>} to create the source — so secrets never travel through an agent conversation. The stash is single-use: it is deleted as soon as setup consumes it, and expires after 24 hours if never consumed.

Required API key scopes

external_data_source:write

Request parameters

  • source_type
  • payload
    object

Response


Example request

POST /api/projects/:project_id/external_data_sources/store_credentials
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/external_data_sources/store_credentials/\
-d source_type=undefined,\
-d payload="object"

Example response

Status 201
RESPONSE
{
"credential_id": "13c40afa-2996-4a0c-b2e9-68fba9462242",
"source_type": "string",
"created_at": "2019-08-24T14:15:22Z",
"expires_at": "2019-08-24T14:15:22Z"
}

List all external data sources stored credentials

List credentials stored via the source connect page that haven't been consumed yet.

Returns metadata only (id, source type, timestamps) — never the secrets themselves. Stored credentials are temporary: they disappear once consumed by setup or when they expire. Newest first, so after a user confirms they've finished the connect page, the first entry for the source type is the one to pass to setup.

Required API key scopes

external_data_source:read

Query parameters

  • search
    string
  • source_type
    string

Example request

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

Example response

Status 200
RESPONSE
{
"credential_id": "13c40afa-2996-4a0c-b2e9-68fba9462242",
"source_type": "string",
"created_at": "2019-08-24T14:15:22Z",
"expires_at": "2019-08-24T14:15:22Z"
}

Retrieve external data sources wizard

Create, Read, Update and Delete External data Sources.

Required API key scopes

external_data_source:read

Query parameters

  • source_type
    string

Example request

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

Example response

Status 200 No response body

Community questions

Questions about this page? or post a community question.