I try to create a charge but I'm receaving this Error: You are not authorized to do that

I creatint a charge first then retrieving address but it comes with authorization error I have used my valid Api key
$apikey = “*********************************”;
$apiVersion = ‘2018-03-22’;
$currency = ‘USDT’;
$amount = 100;
$metadata = array(
‘customer_id’ => ‘123’,
‘customer_name’ => ‘John Doe’
);

// Create the charge
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘https://api.commerce.coinbase.com/charges’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
‘name’ => ‘Deposit’,
‘description’ => ‘Product Description’,
‘pricing_type’ => ‘fixed_price’,
‘local_price’ => array(
‘amount’ => $amount,
‘currency’ => $currency
),
‘metadata’ => $metadata
)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'X-CC-Api-Key: '.$apiKey,
'X-CC-Version: '.$apiVersion
));
$result = curl_exec($ch);
$json = json_decode($result);

// Check if there is an error
if (curl_errno($ch)) {
echo 'Error: ’ . curl_error($ch);
} else if (isset($json->error)) {
echo 'Error: ’ . $json->error->message;
} else {
$chargeId = $json->data->id;

// Retrieve the deposit address
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.commerce.coinbase.com/charges/'.$chargeId.'/addresses');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'X-CC-Api-Key: '.$apiKey,
    'X-CC-Version: '.$apiVersion
));
$result = curl_exec($ch);
$json = json_decode($result);

// Check if there is an error
if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else if (isset($json->error)) {
    echo 'Error: ' . $json->error->message;
} else {
    $address = $json->data->$currency;
    echo 'Deposit address: '.$address;
}

}
curl_close($ch);

Welcome to the Coinbase Cloud Developer forum, @Razaqjuma! To further help you with your concern, we suggest you to open a support ticket with our team with the following details:

  • Please provide a code snippet you are using to create a charge
  • Please provide a screenshot of the error code you are experiencing
  • If you have any more information or screenshot that can demonstrate your concern, feel free to share it with us. Please ensure to send any images or screenshots as attachments, as we’re unable to see images/screenshots when they are inserted in the body of your email and be reminded to omit any personal info.

Upon creating a support ticket, kindly include the link of this forum so that the team will be aware that it’s you. Additionally, please use the email address associated with your Coinbase account.
Thank you and have a nice day!

Thanks. I have already solved the error, it was my own mistake.

Hi @Razaqjuma! We’re glad that your problem has been resolved and we’re always happy to help! Please reach out in the future if you need anything else. Have a great day!