{"library":"posthog-openapi-client","title":"PostHog OpenAPI Client","description":"This package provides a TypeScript client for interacting with the PostHog API, automatically generated from the PostHog OpenAPI schema. It aims to offer a type-safe and convenient way to access PostHog's functionalities programmatically, including managing events, persons, and insights. Currently at version 0.0.12, it is in its early stages of development, meaning the API surface may evolve rapidly and breaking changes are likely before a stable 1.0 release. The package is primarily designed for TypeScript environments and relies on environment variables for API key and base URL configuration. Its key differentiator is providing a pre-generated, typed client, saving developers the effort of manual API request handling and type definition.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install posthog-openapi-client"],"cli":null},"imports":["import { PosthogAPIClient } from 'posthog-openapi-client';","import { PosthogAPIClient } from 'posthog-openapi-client';\nconst client = new PosthogAPIClient({ BASE: '...', TOKEN: '...' });","const response = await client.events.list();"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { PosthogAPIClient } from 'posthog-openapi-client';\n\n// Ensure environment variables are set:\n// export POSTHOG_PERSONAL_API_KEY=YOUR_POSTHOG_API_KEY\n// export POSTHOG_BASE_URL=\"https://eu.posthog.com\" or \"https://app.posthog.com\"\n\nconst baseUrl = process.env.POSTHOG_BASE_URL ?? 'https://app.posthog.com';\nconst apiKey = process.env.POSTHOG_PERSONAL_API_KEY ?? '';\n\nif (!apiKey) {\n  console.error('Error: POSTHOG_PERSONAL_API_KEY environment variable is not set.');\n  process.exit(1);\n}\n\n// Initialize the client with base URL and API key\nconst client = new PosthogAPIClient({\n  BASE: baseUrl,\n  TOKEN: apiKey\n});\n\nasync function fetchSomeData() {\n  try {\n    // Example: Fetch recent events\n    // The actual method names and parameters depend on the generated client's structure.\n    // Assuming 'events' is a service and 'list' is a method on it.\n    const events = await client.events.list({\n      limit: 5,\n      // You might need to specify a project ID or other filters depending on your PostHog setup\n      // project_id: 123,\n    });\n    console.log(`Successfully fetched ${events.results?.length ?? 0} events.`);\n    if (events.results && events.results.length > 0) {\n      console.log('First event:', events.results[0]);\n    }\n\n    // Example: Fetch a list of persons\n    const persons = await client.persons.list({ limit: 3 });\n    console.log(`Successfully fetched ${persons.results?.length ?? 0} persons.`);\n    if (persons.results && persons.results.length > 0) {\n      console.log('First person:', persons.results[0]);\n    }\n\n  } catch (error) {\n    console.error('Failed to interact with PostHog API:', error);\n    if (error instanceof Error) {\n      console.error('Error message:', error.message);\n    }\n  }\n}\n\nfetchSomeData();","lang":"typescript","description":"This quickstart demonstrates how to initialize the `PosthogAPIClient` using environment variables and then make authenticated API calls to fetch events and persons from your PostHog instance.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}