// Construct endpoint URL for listing devices in project.
deviceListUrl := "https://api.d21s.com/v2/projects"
// Create a custom http Client with timeout.
client := &http.Client{Timeout: time.Second * 3}
// Create the request object with method, URL, but no optional body.
req, err := http.NewRequest("GET", deviceListUrl, nil)
// Set the request's Authorization header to use HTTP Basic Authentication.
os.Getenv("DT_SERVICE_ACCOUNT_KEY_ID"),
os.Getenv("DT_SERVICE_ACCOUNT_SECRET"),
// Send an HTTP request and return an HTTP response.
response, err := client.Do(req)
defer response.Body.Close()
// Convert response body to map.
var body map[string]interface{}
if err = json.NewDecoder(response.Body).Decode(&body); err != nil {
// Pretty print the response body.
prettyBody, _ := json.MarshalIndent(body, "", " ")
fmt.Println(string(prettyBody))