How can I get the Token from the server

Working with Postman, using the configeration as shown at the screen shoot, I’m able to get the token from the server.
How can I do this using Golang code?

I found that postman has a ‘snippest’ generator at the maximum right, that could generate Go code

package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://....../oauth2/token"
  method := "POST"

  payload := strings.NewReader("tenant_id=xxxx&client_id=xxxx&client_secret=xxxx&grant_type=xxxx")

 	req, _ := http.NewRequest(method, url, payload)

	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.