Hello Community.
I was trying to get the token on Paypal with a http (module net/http) Post request.
The link to example: example
I tried decode and unmarshall and any way found on the internet.
I want to get the response of the post request.
Simple the result always is empty == [] or == nil.
Ex.
resp, err := http.NewRequest("POST", "https://api-m.sandbox.paypal.com/v1/oauth2/token", (strings.NewReader(data.Encode())))
respBody, err := io.ReadAll(resp.Body) // string(respBody) is "grant_type=client_credentials"
var info []interface{}
json.Unmarshal([]byte(string(respBody)), &info) // info is []
var res interface{}
var someErr = json.NewDecoder(resp.Body).Decode(&res) // res and someErr are <nil>
If i use map[string]interface{} result is map[].
So i guess the response gives the default value of the type.
Expected result should be an object(struct) with access token and other fields.
I saw the examples of how to unmarshal json and so on.
What i am missing.
Though its hard to tell from the inline comment, whter or net string(respBody) is the JSON value "foo=bar" (go "\"foo=bar\"") or the go value "foo=bar"…
I don’t think it has the quotes internally to make it an actual JSON string, but since he’s trying to parse as a map, a string is likely not what he expects.
Thanks all for the help.
I gave it a look again and i was doing it wrong.
I saw some examples in github and realized i was using the req and resp wrong.
So i changed this req, err := http.NewRequest("POST", "https://api-m.sandbox.paypal.com/v1/oauth2/token", (strings.NewReader(data.Encode())))
To do this