Sandbox CreatePayment fails with "Not authorized" despite valid credentials

I’m setting up Square payments for a new sandbox application. My sandbox Application ID, Access Token, and Location ID (Default Test Account) all work correctly when I test CreatePayment through the API Explorer — I get a COMPLETED payment.

However, the exact same Access Token, Location ID, and test source_id (cnon:card-nonce-ok), when sent via a direct server-side API call (Cloudflare Worker calling with Authorization: Bearer ), fail every time with:

- Sometimes: [AUTHENTICATION_ERROR/UNAUTHORIZED] “This request could not be authorized.”
- Sometimes: [INVALID_REQUEST_ERROR/BAD_REQUEST] “Not authorized to take payments with location_id=LNSSGJ6H3YXYB”

I’ve confirmed the token is copied exactly (verified via the Explorer’s own generated code/cURL view), tested from a fresh incognito session, redeployed after each change, and confirmed the Application ID matches across both. Can you check whether this Sandbox application/location has card processing fully enabled, or if there’s an account-level restriction blocking direct API calls?

Application ID: sandbox-sq0idb-dozgAFKnykP7wC39CSEa_g
Location ID: LNSSGJ6H3YXYB

@BeataAdamczyk - There is no enablement required for card processing. Make sure to switch ALL of the following when switching from sandbox to production:

  • Base URL (https://connect.squareupsandbox.com/v2/payments vs https://connect.squareup.com/… )
  • Application ID
  • Location ID

The errors you are receiving (Not authorized to take payments…) is coming from using the sandbox Location ID for calls to your production environment.

Thank you so much for your help.
Beata