# Retrieve data from your endpoint with Go - Docs

Call PostHog endpoints from Go.

## Basic request

Go

PostHog AI

```go
package main
import (
    "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

PostHog AI

```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")
```

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better