> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Retrieve data from your endpoint with Go Canonical URL: https://posthog.com/docs/endpoints/start-here/retrieve-data/go Call PostHog endpoints from Go. ## Basic request ```go package main import ( "encoding/json" "fmt" "net/http" "os" ) func main() { url := "/api/environments/{project_id}/endpoints/{endpoint_name}/run" req, _ := http.NewRequest("GET", url, nil) req.Header.Set("Authorization", "Bearer "+os.Getenv("POSTHOG_PERSONAL_API_KEY")) client := &http.Client{} resp, err := client.Do(req) if err != nil { panic(err) } defer resp.Body.Close() var data map[string]interface{} json.NewDecoder(resp.Body).Decode(&data) fmt.Println(data) } ``` ## With variables ```go import ( "bytes" "encoding/json" ) url := "/api/environments/{project_id}/endpoints/{endpoint_name}/run" body, _ := json.Marshal(map[string]interface{}{ "variables": map[string]string{"customer_id": "cust_123"}, }) req, _ := http.NewRequest("POST", url, bytes.NewBuffer(body)) req.Header.Set("Authorization", "Bearer "+os.Getenv("POSTHOG_PERSONAL_API_KEY")) req.Header.Set("Content-Type", "application/json") ```