x

Square Payment Gateway: Request not authorized error

Hi Experts!

I am new to square payment gateway. I have a php website where i want to charge a card for payment. I have created account in square and created an application.  Now i want to test in sandbox mode, so i do have sandbox access token and location-id  so far I am successful in generating the form, but when i submit the form i get the below error:

category    AUTHENTICATION_ERROR
code            UNAUTHORIZED
detail    This request could not be authorized.

in response, So kindly guide me through this issue.

 

FYI, i generated the form via below link:

https://github.com/square/connect-api-examples/tree/master/templates/web-ui/payment-form/basic

Regards,
Ali

20,569 Views
Message 1 of 14
Report
1 Best Answer
Admin

Best Answer

Hey @ahsanali, I escalated your question to an API Specialist who confirmed that the AUTHENTICATION_ERROR message you received occurs when your Application ID and Personal Access Token do not match the information in your Developer Portal. Please make sure your Application ID and Personal Access Token are accurately updated in your sqpaymentform.js and your process-card files.

Feel free to also view our Developer Documentation for information on troubleshooting errors.

️ Helen
Seller Community Manager

View Best Answer >

20,548 Views
Message 3 of 14
Report
13 REPLIES 13

FYI, i copied the error from the response of below url via browser console
https://pci-connect.squareup.com/v2/card-nonce?_=1545914[Redacted]

20,523 Views
Message 2 of 14
Report
Admin

Best Answer

Hey @ahsanali, I escalated your question to an API Specialist who confirmed that the AUTHENTICATION_ERROR message you received occurs when your Application ID and Personal Access Token do not match the information in your Developer Portal. Please make sure your Application ID and Personal Access Token are accurately updated in your sqpaymentform.js and your process-card files.

Feel free to also view our Developer Documentation for information on troubleshooting errors.

️ Helen
Seller Community Manager

20,549 Views
Message 3 of 14
Report

Thanks Helen,

 

You were correct!

 

My bad,

added sandbox access token instead of sandbox application id

😞

 

 

20,493 Views
Message 4 of 14
Report

I also face same issue as below

 

Square payment error: Error calling ListLocations: {"errors":[{"category":"AUTHENTICATION_ERROR","code":"UNAUTHORIZED","detail":"This request could not be authorized."}]}.

 

please let me know how to make sandbox request authorized for testing

17,436 Views
Message 5 of 14
Report

Hello, Helen.

I am stuck with problems and will be glad if you help me.

I am new to square and my problem is "request not authorized error".

I followed the steps of documentation, and if I click Pay button, then the javascript alerts "request not authorized error.".

Please help me.

 

11,047 Views
Message 6 of 14
Report
Admin

Hi @Crystal-Moon! Thanks for reaching out. Make sure you have a completely verified and set up account that is approved to accept credit cards. If your identity has not been approved, then you will also receive that error.

AshleyK
Community Moderator, Square
Sign in and click Mark as Best Answer if my reply answers your question.
11,036 Views
Message 7 of 14
Report
Square Community Moderator

@amchauhan  Did you get a chance to read @Helen 's Best Answer above?

It looks like she reached out to the API team and posted the solution for this error there!

Ashley C
Community Moderator, Square
Sign in and click Mark as Best Answer if my reply answers your question.
17,418 Views
Message 8 of 14
Report

As per your suggestion I have follow all step still error remain same, at a time of listLocation menthod call

//get list of all locations
var listLocationsResponse = locationsApi.ListLocations();

above method throw exception as mentioned below

 

Square payment error: Error calling ListLocations: {"errors":[{"category":"AUTHENTICATION_ERROR","code":"UNAUTHORIZED","detail":"This request could not be authorized."}]}.

 

please let me know what can i do

 

17,356 Views
Message 9 of 14
Report

Hello,

 

I have configure sandbox application id and sandbox access token of default authorized account and also set return url to square sandbox account but still when LocationApi call, this exception accour

 

Square payment error: Error calling ListLocations: {"errors":[{"category":"AUTHENTICATION_ERROR","code":"UNAUTHORIZED","detail":"This request could not be authorized."}]}.

 

we can not fetch sandbox account locations through api call please let me know how to resolve this error

17,300 Views
Message 10 of 14
Report
Square Community Moderator

Hi @amchauhan!

 

I reached out to the API channel and they said the error you're getting is due to having credentials mismatched or the base path URL not configured to the right environment.

Ashley C
Community Moderator, Square
Sign in and click Mark as Best Answer if my reply answers your question.
16,862 Views
Message 11 of 14
Report

Im having the same problem. I've double checked, and even reissued the key

I got fed up and went and tried it on your page https://developer.squareup.com/explorer/square_2019-12-17/oauth-api/obtain-token

Same error. I'm copying and pasting the id and key, as well as the code thats returned from /oauth2/authorize



that said, the dashboard has malfunctioned SEVERAL times. firstly it was not saving my Redirect URL, I'd add it then try it would error, id come back and it would be cleared out.
About 6 times i had to enter it before it would save, now thats working.
DUring testing why this unauth error is coming up, I "replaced token" this also doesnt reflect an update, had to log out then back in two times before it created a new one..

Anyway SAME problem..

curl https://connect.squareup.com/oauth2/token \
  -X POST \
  -H 'Square-Version: 2019-12-17' \
  -H 'Content-Type: application/json' \
  -d '{
    "client_id": "sq0idp-Lno1QXpjx8Z2Avemg3orUg",
    "client_secret": "DIRECTCOPYANDPASTE",
    "grant_type": "authorization_code",
    "code": "sq0cgp-B2KYptDrmgYoZ3Kii1M1dw"
  }'

 

cache-control: no-cache
content-length: 70
content-type: application/json
date: Sat, 16 May 2020 23:02:53 GMT


{ "message": "Not Authorized", "type": "service.not_authorized" }
14,147 Views
Message 12 of 14
Report

I'm also having the same issue. Is there any sort of permission that needs to be granted?

10,877 Views
Message 13 of 14
Report
Alumni

@ashc gave some insight provided by the API Team above. If you still need help, reach out to our Support Team. From there, your case will be escalated to our API Team. 

Justin
Community Moderator, Square
Sign in and click Mark as Best Answer if my reply answers your question.
10,867 Views
Message 14 of 14
Report