Retrieve data from your endpoint with TypeScript
Call PostHog endpoints from TypeScript with type safety.
Basic request
typescript
With variables
typescript
For fully type-safe SDKs generated from your endpoint schemas, see OpenAPI SDK generation.






Call PostHog endpoints from TypeScript with type safety.
interface EndpointResponse {results: Record<string, unknown>[];columns: string[];hasMore: boolean;}async function callEndpoint(endpointName: string): Promise<EndpointResponse> {const response = await fetch(`<ph_app_host>/api/environments/{project_id}/endpoints/${endpointName}/run`,{headers: {"Authorization": `Bearer ${process.env.POSTHOG_PERSONAL_API_KEY}`}});return response.json();}const data = await callEndpoint("daily_active_users");
async function callEndpoint(endpointName: string,variables: Record<string, string>): Promise<EndpointResponse> {const response = await fetch(`<ph_app_host>/api/environments/{project_id}/endpoints/${endpointName}/run`,{method: "POST",headers: {"Authorization": `Bearer ${process.env.POSTHOG_PERSONAL_API_KEY}`,"Content-Type": "application/json"},body: JSON.stringify({ variables })});return response.json();}const data = await callEndpoint("customer_events", { customer_id: "cust_123" });
For fully type-safe SDKs generated from your endpoint schemas, see OpenAPI SDK generation.