Retrieve data from your endpoint with Python

Call PostHog endpoints from Python using the requests library.

Basic request

Python
import requests
url = "<ph_app_host>/api/environments/{project_id}/endpoints/{endpoint_name}/run"
headers = {"Authorization": "Bearer {POSTHOG_PERSONAL_API_KEY}"}
response = requests.get(url, headers=headers)
data = response.json()
print(data)

With variables

Python
import requests
url = "<ph_app_host>/api/environments/{project_id}/endpoints/{endpoint_name}/run"
headers = {"Authorization": "Bearer {POSTHOG_PERSONAL_API_KEY}"}
body = {"variables": {"customer_id": "cust_123"}}
response = requests.post(url, headers=headers, json=body)
data = response.json()

Community questions

Was this page useful?

Questions about this page? or post a community question.