PHP cURL { "errors": [ { "category": "AUTHENTICATION_ERROR", "code": "UNAUTHORIZED", "detail": "This request could not be authorized." } ] }

Any idea why this code is getting an UNAUTHORIZED error? It got a 200 response in the API explorer with the exact token, key and loc id I used.

{ “errors”: [ { “category”: “AUTHENTICATION_ERROR”, “code”: “UNAUTHORIZED”, “detail”: “This request could not be authorized.” } ] }

The token, Idempotency key and Location ID are directly from the generated API example in the API explorer and appear to perfectly match what I have generated for the sandbox test.

$headers['Square-Version'] = '2023-09-25';
$headers['Authorization'] = 'Bearer I put the sandbox token i prev generated here';
$headers['Content-Type'] = 'application/json';

$form['idempotency_key'] = 'I put the idem key here';

$form['quick_pay']['location_id'] = 'I put location id for test account here';
$form['quick_pay']['name'] = 'Test Name';
$form['quick_pay']['price_money']['amount'] = '12500';
$form['quick_pay']['price_money']['currency'] = 'USD';

$form = http_build_query($form);

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, '');

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_POSTFIELDS, $form);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($curl);

echo $result;



An authorization only happens if credentials or the environment are misconfigured/malformed. If you print the request are there any malformed values? :slightly_smiling_face: