Dear All,
I’m getting following error no matter i have set the correct values. I was trying almost 4 days by now and still no result.

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

My function is a follows and i’m 100% sure about the credintials as same request working from Postman Json post.
Since this is a Laravel Program. I’m testing in my localhost:8000. is that the issue ?

public function get_squre_checkout_url($data){

        $headers['Square-Version'] = '2024-01-18';
        $headers['Authorization'] = $data['auth'];
        $headers['Content-Type'] = 'application/json';
        $my_data = [
            "idempotency_key" => $data['idempotency_key'],
            "quick_pay" => [
                  "name" => $data['name'], 
                  "price_money" => [
                     "amount" => $data['amount'], 
                     "currency" => $data['currency'] 
                  "location_id" => $data['location_id'] 
            "checkout_options" => [
                        "allow_tipping" => false, 
                        "ask_for_shipping_address" => false, 
                        "enable_coupon" => false, 
                        "enable_loyalty" => false, 
                        "merchant_support_email" => $data['merchant_support_email'], 
                        "redirect_url" => $data['redirect_url'], 
                        "accepted_payment_methods" => [
                           "afterpay_clearpay" => true, 
                           "apple_pay" => true, 
                           "cash_app_pay" => false, 
                           "google_pay" => true 
            "description" => $data['description'] 

        $my_request = http_build_query($my_data);
        $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, $my_request);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec($curl);
        return $result;


Please help me to get this sorted. i’m very new to Square Development and this is my 5th day with square yet.

looking forward to hearing from you.

Hi @Thuzi ,

That error likely means your having an API credential issue within your application. Likely, the access token.

  1. Try double checking how you’ve stored your access token. Try making print calls to see if saved like you expected. For more information about Access Tokens, checkout our doc.
  2. If you feel the access token is in place, try a GET API call, to simplify the POSt request body complication. I would suggest a call to ListLocations.
  3. If you can get the ListLocations API call working, try double checking your API call. You noted it worked in postman. We also offer a Postman library. To test API calls, we also have an API Explorer.

Also try double checking your $my_request, see if is a JSON string.