Custom REST source

Let AI connect your sources for you

Skip the manual setup — run this in your project and the wizard auto-detects your databases and APIs and connects them to PostHog.

Learn more
PostHog Wizard hedgehog

The Custom REST source lets you connect any REST API to PostHog's Data Warehouse without waiting for a dedicated integration. You configure the connection using the source builder in the PostHog UI – setting the base URL, authentication, pagination, and the tables (endpoints) you want to sync – and PostHog handles the rest.

This is useful when:

  • The API you need isn't available as a managed source
  • You want to prototype a connection quickly
  • You need to pull data from an internal or niche API

Create a custom REST source

  1. In PostHog, go to the Data pipeline sources tab.
  2. Click + New source and select Custom REST source.
  3. Configure your source using the builder (see Configuration reference below):
    • Enter the Base URL for the API (e.g. https://api.example.com/v1)
    • Select your Authentication type and enter your credentials
    • Add any Default headers the API requires
    • Add one or more Tables – each table maps an API endpoint to a table in your Data Warehouse
  4. Click Next. PostHog validates the configuration, checks that the URLs are reachable, and probes the first few endpoints to confirm your credentials work.
  5. Configure sync settings (sync method, frequency) for each table, then start syncing.

Configuration reference

Base URL

The root URL that all table paths are resolved against (e.g. https://api.example.com/v1). On PostHog Cloud, all URLs must use https://.

Authentication

Select an authentication type from the Authentication dropdown.

TypeFieldsDescription
No auth–No authentication. Use for public APIs.
Bearer tokenTokenSends an Authorization: Bearer <token> header with every request.
API keyLocation, Header/parameter name, KeySends the key as a header, query parameter, or cookie.
HTTP basic authUsername, PasswordSends HTTP Basic credentials with every request.
OAuth2Client ID, Client secret, Token URL, Grant type, Refresh token (for refresh_token grant)Authenticates via OAuth2. Supports client_credentials and refresh_token grants.

Credentials are stored encrypted and never exposed in API responses.

OAuth2 configuration

OAuth2 authentication supports two grant types:

  • client_credentials – Machine-to-machine authentication. The source exchanges the client ID and client secret for an access token. No user interaction is required.
  • refresh_token – The source uses a pre-obtained refresh token (along with the client ID and secret) to mint access tokens. Use this for APIs where you've already completed an authorization flow outside PostHog.

The authorization_code grant is not supported.

FieldRequiredDescription
Client IDYesThe OAuth2 client ID.
Client secretYesThe OAuth2 client secret. Stored encrypted and never returned in API responses.
Token URLYesThe endpoint PostHog calls to mint access tokens (e.g. https://auth.example.com/oauth/token). Cannot be changed after the source is created.
Grant typeYesclient_credentials (default) or refresh_token.
Refresh tokenFor refresh_token grantA pre-obtained refresh token. Required when using the refresh_token grant type. Stored encrypted and never returned.
ScopesNoSpace-separated OAuth2 scopes, if the provider requires them.
Client auth methodNoHow credentials are sent to the token endpoint: body (form parameters, default) or basic (HTTP Basic).

Default headers

Optional key-value pairs sent with every request. Auth headers are added automatically based on your authentication configuration – you don't need to duplicate them here.

Tables

Each table maps an API endpoint to a table in your Data Warehouse. You can add up to 50 tables per source.

Click Add table to add a new table. Each table has the following fields:

FieldDescription
Table nameThe table name in PostHog. Must be unique within the source.
Primary keyColumn(s) used for deduplication during incremental sync (e.g. id). Separate multiple keys with commas.
PathURL path appended to the base URL (e.g. /v1/users).
HTTP methodGET (default) or POST.
Records JSONPathPath to the array of rows in each API response (e.g. data, items, results.data).

Pagination

Select a Paginator type for each table. This tells PostHog how to fetch all pages of data from the endpoint.

TypeFieldsDescription
Single page–No pagination. The endpoint returns all data in one response.
JSON body next-URLNext-URL JSONPathThe response body contains a URL to the next page.
Cursor in JSON bodyCursor JSONPath, Cursor query paramThe response contains a cursor token passed back as a query parameter.
Offset / limit query paramsPage size, Offset param, Limit paramClassic offset/limit pagination.
Page number query paramPage query param, Initial pagePage-based pagination.
Link header (RFC 5988)rel= key in Link headerFollows the Link header to the next page.

Incremental sync

Enable Incremental sync on a table to only fetch new or updated records on subsequent syncs instead of re-fetching everything.

FieldDescription
Cursor JSONPathThe field in each record used as the sync cursor (e.g. updated_at). Required when incremental sync is enabled.
Cursor query paramQuery parameter name to send the cursor value (e.g. since).
Cursor typeType of the cursor field: Datetime (default), Date, Timestamp (epoch), or Integer.
Upstream row orderWhether the API returns rows in ascending (oldest first) or descending (newest first) order. Pick Descending when the API returns newest rows first – otherwise a resumed sync may skip rows.

Example configurations

Paginated API with bearer token

To sync users and orders from an API that uses cursor pagination:

  1. Set Base URL to https://api.myservice.com/v2
  2. Set Authentication to Bearer token and enter your token
  3. Add a table named users with path /users and Cursor in JSON body pagination (cursor JSONPath: meta.next_cursor, cursor query param: cursor)
  4. Add a second table named orders with the same pagination. Enable Incremental sync with cursor JSONPath updated_at and cursor query param updated_since

API key in query parameter

To sync contacts from an API that authenticates via a query parameter:

  1. Set Base URL to https://data.example.com/api
  2. Set Authentication to API key, location to Query parameter, parameter name to apikey, and enter your key
  3. Add a table named contacts with path /contacts, records JSONPath results, and Offset / limit query params pagination (page size: 200)

POST-based query endpoint

Some APIs require POST requests to query data. The builder supports this:

  1. Set Base URL to https://analytics.example.com
  2. Set Authentication to Bearer token and enter your token
  3. Add a table named events with path /query/events and HTTP method POST
  4. Set the paginator to JSON body next-URL with next-URL JSONPath next_page_url

Build from API docs with AI

Instead of configuring the source by hand, you can give PostHog a link to the API documentation. PostHog then drafts the configuration for you.

This feature needs AI data processing enabled for your organization. PostHog sends the documentation to an AI model, so an organization admin must approve this first. The Build a custom source from API docs screen appears only when the feature is turned on for your organization.

To build a source from API docs:

  1. In PostHog, go to the Data pipeline sources tab and select Custom REST source.
  2. On the Build a custom source from API docs screen, enter a Source name (for example, Acme CRM).
  3. Enter the Documentation URL for the API.
  4. Click Generate. PostHog fetches the documentation and drafts the configuration. It checks the draft against the same rules as manual setup and retries a few times if the check fails.
  5. Review the draft in the source builder. Adjust the base URL, tables, pagination, or incremental sync as needed.
  6. Enter your credentials. The draft never includes secrets.
  7. Click Next to validate and create the source.

To skip the AI step, click Configure manually to open the source builder.

Review the draft before you create the source

The draft is a starting point. Check that pagination, Records JSONPath, and incremental sync cursors match how the API works.

Preview and validate configuration

Before you create a source, you can read sample rows from one table. Use the sample to check your Records JSONPath, Primary key, and Cursor JSONPath values.

The preview reads one page of live data from the API. It returns up to 50 rows (10 by default) and the column names with an inferred type for each column. The rows are the records that a sync would ingest.

The preview is available through the PostHog API and the MCP server. In MCP, use the external-data-sources-preview-resource tool. You pass the table name, the manifest, and the credential for your authentication type.

PostHog reports errors in two ways:

  • If the configuration is invalid, or the URL check fails, the API returns a 400 error.
  • If the live read fails (for example, the host is unreachable or the API returns an auth error), the API returns a 200 response. The error field has the message and rows is empty.

Limitations

  • Maximum 5 custom sources per team
  • Maximum 50 tables per source
  • Only GET and POST HTTP methods are supported
  • All URLs must use https:// on PostHog Cloud
  • URLs pointing to internal or private network hosts are blocked on PostHog Cloud

Troubleshooting

Credential validation fails at creation

PostHog probes the first few endpoints when you create a source. If the API returns HTTP 401 or 403, check that:

  • You selected the correct authentication type
  • The credentials you entered are valid and have the required permissions
  • For API key auth, the location and parameter name match what the API expects

Other status codes (404, 429, 5xx) don't block source creation – those errors surface on the first sync instead.

Validation errors

Common issues:

  • Missing base URL – The base URL is required
  • No tables – You need at least one table
  • Duplicate table names – Each table name must be unique
  • Invalid HTTP method – Only GET and POST are supported

Incremental sync skips rows

If using Ascending upstream row order (the default) and the API doesn't guarantee ascending order by the cursor field, rows can be skipped when a sync is interrupted and resumed. Set Upstream row order to Descending if the API returns newest records first.

OAuth2 token errors

If an OAuth2 source's token expires or is revoked, the source fails with a TOKEN_REFRESH_FAILED error. To reconnect:

  1. Edit the source settings.
  2. Re-enter the Client secret and (for refresh_token grant sources) the Refresh token.
  3. Save the source. PostHog validates the new credentials and clears the error once a token is successfully minted.

Still have questions?

Was this page useful?