Retrieve data from your endpoint with Python
Contents
Call PostHog endpoints from Python using the requests library.
Basic request
Python
With variables
Python
Call PostHog endpoints from Python using the requests library.
import requestsurl = "<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)
import requestsurl = "<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()
Questions about this page? or post a community question.