Post
Topic
Board Service Discussion
Authentication failed with the Coinbase API
by
w_t
on 31/03/2018, 06:19:44 UTC
Goodmorning everyone,
I have an authentication problem with my account, through the Coinbase.com API.

I tell you what's happening to me:

- I opened a private account on Coinbase.com,
- I created my API Keys,
- I have enabled all the permissions to the keys, this means that I can perform all the operations possible with those APIs.
- I read the developer's guide and I tried to write a small script to test the authentication, but nothing completely useless ..., I return this error:

Code:
string(237) "{"errors":[{"id":"authentication_error","message":"invalid signature"}],"warnings":[{"id":"missing_version","message":"Please supply API version (YYYY-MM-DD) as CB-VERSION header","url":"https://developers.coinbase.com/api#versioning"}]}"

Since the examples are in other languages ​​but I use PHP, I think I have made a mistake during the conversion of the script.

This is the link of the official guide:

https://developers.coinbase.com/docs/wallet/api-key-authentication

This is my script:

Code:
$API_KEY = '<---MY API KEY--->';
$API_SECRET = '<---MY API KEY SECRET--->';

$body = '';
$timestamp = time();
$message = $timestamp . 'GET' . 'https://www.mysite.it' . $body;
$signature = hash_hmac('SHA256', $message, $API_SECRET);

$headers = array(
'CB-ACCESS-SIGN: '.$signature,
'CB-ACCESS-TIMESTAMP: '.$timestamp,
'CB-ACCESS-KEY: '.$API_KEY
);

$api_url = 'https://api.coinbase.com/v2/user';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);

$data = curl_exec($ch);


if(curl_errno($ch))
{
    echo "Errore: " . curl_error($ch);
}
else
{
    var_dump($data);
    curl_close($ch);
}
?>

Do you give me your opinion?
I've been stuck here for 5 days and I can not understand what I'm missing.
The assistance of Coinbase does not answer me and I have a project to deliver blocked.

Thank you very much for any useful advice.