WebPayments SDK backend to Square API Auth failure

I’m still working in sandbox and the Client-Server Backend in the SDK is working great locally. I am getting valid card tokens, and the Client /examples/card.html is able to call the server.js storeCard() function.

However I get 401 unauthorized when the Node backend server tries to call the Square API.

const { result, statusCode } = await square.cardsApi.createCard(cardReq);

[Object: null prototype] {
category: ‘AUTHENTICATION_ERROR’,
code: ‘UNAUTHORIZED’,
detail: ‘This request could not be authorized.’
}

I have my sandbox square access token set in the .env.sandbox file.

I am using: npm run dev

I realize there is a different URL for the Client ajax/fetch calls between sandbox and production:

src=“https://sandbox.web.squarecdn.com/v1/square.js

is there also a different URL for the Square API, and if so, where do I set that?

Or what am I missing?

SOLVED - I’m an idiot. I had my appId in the .env.sandbox not my access token.

An AUTHENTICATION_ERROR is a configuration error. Is the location_id that’s configured the one that belongs to the application and access token? Also is the backend calling the right base path URL? It should be calling: connect.squareup.com/v2/payments. :slightly_smiling_face:

where do I find the base path URL to confirm: connect.squareup.com/v2/payments?

Are you using the quickstart? If so then you don’t need to worry about checking cause the environment is selected when you run the command line. If you take the access token and call ListLocations is the configured location returned? :slightly_smiling_face: