"invalid api key" on coinbase prime API

Hi everyone, I’m trying to access the endpoint https://api.prime.coinbase.com/v1/portfolios and I’m getting the error “invalid api key”.

Can you help me?

Some information:

  • I confirmed that the api key was created in coinbase prime;
  • The api key appears as “activated”;
  • The api key was created more than 48 hours ago and I received the email saying that it was active.

Here is the code I’m using for testing (PHP)…

$KEY = '';
$PASSPHRASE = '';
$SECRET = '';
$ENDPOINT = '/v1/portfolios';
$URL = 'https://api.prime.coinbase.com'.$ENDPOINT;
$TIME = time();
$SIGNATURE = $TIME . 'GET' . $ENDPOINT;
$SIGNATURE = base64_encode(hash_hmac('SHA256', $SIGNATURE, $SECRET));
$HEADER = [
      'X-CB-ACCESS-KEY: '. $KEY,
      'X-CB-ACCESS-PASSPHRASE: '. $PASSPHRASE,
      'X-CB-ACCESS-SIGNATURE: ' . $SIGNATURE,
      'X-CB-ACCESS-TIMESTAMP: ' . $TIME,
      'Content-Type: application/json; charset=UTF-8',
      'User-Agent: request'
];
$CURL = curl_init();
curl_setopt_array($CURL, array(
        CURLOPT_URL => $URL,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_HTTPHEADER => $HEADER
));
$CURLRESPONSE = curl_exec($CURL);
2 Likes