Invalid_token message on Golang GET request

I am trying to build a golang REST client for the CB api and continually get the following message:

{"errors":[{"id":"invalid_token","message":"The access token is invalid"}]}

I have confirmed I can access the time and currency APIs successfully.

I’ve also confirmed that the api_url and the endpoints render properly.
I’ve confirmed that the nonce returns properly and is aligned with the time api.

What am I missing?

	req, _ := http.NewRequest("GET", api_url+"accounts", nil)

	// create a signature
	nonce := strconv.FormatInt(time.Now().Unix(), 10)
	fmt.Println(nonce)
	data := nonce + req.Method + req.URL.Path

	mac := hmac.New(sha256.New, []byte(c.apiSecret))
	mac.Write([]byte(data))
	sign := hex.EncodeToString(mac.Sum(nil))

	req.Header.Add("CB-ACCESS-SIGN", sign)
	req.Header.Add("CB-ACCESS-TIMESTAMP", nonce)
	req.Header.Add("CB-ACCCESS-KEY", c.apiKey)

	resp, _ := c.client.Do(req)

Hello @smartinez! Thank you for taking an interest in trying out Coinbase APIs. For the details regarding your concern, we will check on this for you with our team. We will get back to you once we have more information. Keep in touch!

1 Like

Hello @smartinez. We appreciate your patience while we checked this with our team. To further assist you with your issue, we’ll need you to provide us with the following information:

  • Which authorization and authentication method are you trying to use - OAuth2 protocol or API Key?

If you’re trying to use OAuth2 protocol, an API key is no longer needed. You will need to generate a valid access token and refresh tokens instead. You may explore more about its integration at https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/sign-in-with-coinbase-integration.

Moreover, if you’re trying to use API key authentication, you will need to create an API key from your Coinbase account (https://www.coinbase.com/settings/api). You may visit https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-key-authentication for more information.

Once you send us the information requested above, we’ll work to quickly address this issue.

Thank you!

4 Likes

Hi Rita,

I already created an API key above and successfully connected with the Python client. However I do not see any difference between what’s here in Golang and what the instructions entail about how to create the signature.

1 Like

Hi @smartinez, thank you for providing this additional information. Our team couldn’t spot anything within the code snippet you’ve provided for Golang that would explain this error.

Please also note that we are limited in the support we provide for specific programming languages. Based on your description, this could be associated with the Golang programming language or with different frameworks you are utilising, since everything works on your Python client.

We would also advise checking the differences between the OAuth2 protocol and API Keys, as the error you are encountering is associated with OAuth2, but the code snippet you’ve provided is to generate a signature when utilizing an API Key

3 Likes