API authentication_error

Hi,

I’ve an error that I can’t understand and fix. The most weird thing is my code is OK for the path /v2/exchange-rates?currency=USD but the path /v2/accounts gives an error.

I use a tool that you probably don’t know named Webdev (it’s a french IDE) and my code is :

sAPIKey 		is a string = "xxx"
sSecretKey 	    is a string = "xxx"
sTimeStamp	    is a string
sStringToSign	is a string
sSignature		is a string
sMethod         is a string = "GET"
sPath           is a string = "/v2/accounts" // "/v2/exchange-rates?currency=USD"
MyRequest	    is a restRequest
MyResponse	    is a restResponse
MyJSON		    is a JSON

// Creation of the timestamp
MyRequest.URL		= "https://api.coinbase.com/v2/time" 
MyResponse			= RESTSend(MyRequest)
MyJSON				= MyResponse.Content
sTimeStamp			= MyJSON.data.epoch

// Creation of the signature
sStringToSign		= sTimeStamp + sMethod + sPath
sSignature			= getHMACSignature(sStringToSign, sSecretKey)

MyRequest.URL =  "https://api.coinbase.com/v2/accounts" 

// Creation of the header request
MyRequest["CB-ACCESS-KEY"]			        = sAPIKey
MyRequest["CB-ACCESS-SIGN"]			        = sSignature
MyRequest["CB-ACCESS-TIMESTAMP"]            = sTimeStamp

// Calling the API
MyResponse							        = RESTSend(MyRequest)
MyJSON								        = MyResponse.Content

MyJSON content is :
errors
[1]
id = authentication_error
message = invalid signature

I’ve trying to add spaces or ‘’ between the strings in the sStringToSign but MyJSON is still the same.

Someone has an idea ?

Thank you for your help.

Hi,

I fixed the problem : the signature must have to be in lower case.
In fact, the API documentation makes you believe the path /v2/exchange-rates?currency=USD use the header request but this is not the case, so the signature isn’t use in this case : it can be wrong and the result is OK

2 Likes