Sandbox credentials

Hello, I have created a test application which is currently in sandbox mode. When I am trying to charge a test card using the connect API I am getting Not Authorized error.

:wave: When you get the not authorized error that means that the credentials or the environment isn’t correctly configured. :slightly_smiling_face:

Hello,
I am using the following set of credentials -
Location id : LY0HVM1W81FNS
Sandbox Application ID : sandbox-sq0idb-hSa1tfIZy04h4QOYgWYiww
Sandbox Access Token : ACCESS_TOKEN

and here is a request I sent to the charge API -
Array
(
[card_nonce] => cnon:CBASEBqqMQwGD10AKt9h-gWIogU
[amount_money] => Array
(
[amount] => 1100
[currency] => USD
)

[idempotency_key] => 61b386a31c959

)

This is the response I am getting as an error -
SquareConnect\ApiException Object
(
[responseBody:protected] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[category] => AUTHENTICATION_ERROR
[code] => UNAUTHORIZED
[detail] => This request could not be authorized.
)

            )

    )

My account has been configured for sandbox environment.
Is the charge API itself different for sandbox and live environment?
Thanks,
Jitendra

In the future please don’t share the access token. Those are secrete. Also what environment is the client configured to? Is it production or sandbox?

OK I will keep that in mind.
It is configured for Sandbox environment

Everything looks to be correct. The payment request is formatted correctly and the source_id is generated from the application ID you provided in the sandbox environment. The only thing that can cause this error is that the client isn’t correctly configured. If you try to make another API call to ListLocations with your client do you get the same error? Also if it succeeds is the returned location this one LY0HVM1W81FNS from the payment request?

No ,the API call ListLocations also returns the same error.
I got this LY0HVM1W81FNS from Locations section in the portal.

Okay, that definitely means that something isn’t configured correctly if you’re getting the not authorized error with ListLocations. What SDK are you using?

Hello,
We are using SDK Package Version: 2.1.0
Thanks,
Jitendra

I can confirm that the location_id and the access token are correct for making calls to the sandbox environment. You’ll need to make sure that you’re also using the sandbox access token and you have the base path URL configured to sandbox.

This is the host url set in the library - https://connect.squareup.com

That’s used for making production API calls. You’ll need to use https://connect.squareupsandbox.com to make API calls with your sandbox credentials. :slightly_smiling_face:

okay, so I changed the host url in the library and I got this now -
SquareConnect\ApiException Object
(
[responseBody:protected] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[category] => INVALID_REQUEST_ERROR
[code] => GONE
[detail] => The request could not be completed since access to the target resource is no longer available.
)))

Is there a reason you’re calling the Transactions API? It’s deprecated. You should be using the Payments API.

Actually, we have integrated with Square Connect a few years ago and some of our clients are using that on live. So, we needed to test out a few things on that API.

Okay! So you’ll need to use a prior version of Square APIs. The most resent version that supports the Transactions API is 2021-09-15. The Transactions API are removed from Square API version 2021-10-20 and later. These endpoints will work if you are using Square API versions prior to 2021-10-20. However, these endpoints will eventually be retired from all Square versions. :slightly_smiling_face:

I see, is there a timeline to when we can expect the new changes as we would have to make changes in our integration as well?
Thanks,
Jitendra

At this time the Transactions API retirement is TBD, but we highly recommend moving to the Payments API. :slightly_smiling_face: