Retrieve data from your endpoint with Go
Contents
Call PostHog endpoints from Go.
Basic request
Go
package mainimport ("encoding/json""fmt""net/http""os")func main() {url := "<ph_app_host>/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 := "<ph_app_host>/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")