# Response status code was not ok: 401

**URL:** <https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110>\
**Category:** Questions\
**Tags:** orders-api, sandbox\
**Created:** [July 27, 2023, 7:06pm UTC](https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110 "2023-07-27T19:06:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xocrates](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/xocrates/32/2136_2.png) [@xocrates](https://developer.squareup.com/forums/u/xocrates)\
**Post date:** [July 27, 2023, 7:06pm UTC](https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110/1 "2023-07-27T19:06:14Z")

</div>

Hi,

I cloned [[https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/node\_orders-payments](https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/node_orders-payments)]([https://V2](https://V2) node\_orders-payments) and entered in my correct ENV tokens for my Sanbox application **Order-Ahead App**.

I first ran:

```auto
npm install

```

with no issue.

And next ran:

```auto
npm test

```

I am now getting the following Browser response:

 ![Screenshot 2023-07-27 at 2.00.54 PM](https://global.discourse-cdn.com/square/original/2X/8/81958e4f674ca1ea4710bd96d51f39c085724eb8.png)

and in my terminal:

```auto
Retrieving currency failed: ApiError: Response status code was not ok: 401.
    at /Users/swim/Documents/GitHub/Square/connect-api-examples/connect-examples/v2/node_orders-payments/node_modules/@apimatic/core/lib/http/requestBuilder.js:367:23
    at DefaultRequestBuilder.<anonymous> (/Users/swim/Documents/GitHub/Square/connect-api-examples/connect-examples/v2/node_orders-payments/node_modules/@apimatic/core/lib/http/requestBuilder.js:179:50)
    at step (/Users/swim/Documents/GitHub/Square/connect-api-examples/connect-examples/v2/node_orders-payments/node_modules/@apimatic/core/node_modules/tslib/tslib.js:193:27)
    at Object.next (/Users/swim/Documents/GitHub/Square/connect-api-examples/connect-examples/v2/node_orders-payments/node_modules/@apimatic/core/node_modules/tslib/tslib.js:174:57)
    at fulfilled (/Users/swim/Documents/GitHub/Square/connect-api-examples/connect-examples/v2/node_orders-payments/node_modules/@apimatic/core/node_modules/tslib/tslib.js:164:62)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  request: {
    method: 'GET',
    url: 'https://connect.squareupsandbox.com/v2/locations/main',
    headers: {
      authorization: 'Bearer undefined',
      'user-agent': 'Square-TypeScript-SDK/22.0.0 (2022-09-21) node/18.14.0 (darwin) ',
      'Square-Version': '2022-09-21'
    }
  },
  statusCode: 401,
  headers: {
    date: 'Thu, 27 Jul 2023 18:54:52 GMT',
    'content-type': 'application/json',
    'content-length': '161',
    connection: 'close',
    'cf-ray': '7ed717ea6e04b12f-ATL',
    'cf-cache-status': 'DYNAMIC',
    'strict-transport-security': 'max-age=631152000; includeSubDomains; preload',
    vary: 'Origin, Accept-Encoding',
    'x-content-type-options': 'nosniff',
    'x-download-options': 'noopen',
    'x-frame-options': 'SAMEORIGIN',
    'x-permitted-cross-domain-policies': 'none',
    'x-sq-dc': 'sjc2b',
    'x-sq-envoy-safe-auth-decision': 'UNAUTHORIZED',
    'x-sq-region': 'sjc2b',
    'x-xss-protection': '1; mode=block',
    'set-cookie': [
      '__cf_bm=hhDEn_nS876xL9FWLUCno3B2j9gDngJ1rc60.ObNmXU-1690484092-0-AWgjVT04EfySp4vmfU2k/BJG64z9VKQ23aDSbdvuhvfq7GnofDQEPDg9ZL9aKQZikZElTSfCQmAaHMtpBlX2qOE=; path=/; expires=Thu, 27-Jul-23 19:24:52 GMT; domain=.squareupsandbox.com; HttpOnly; Secure; SameSite=None'
    ],
    server: 'cloudflare'
  },
  body: '{\n' +
    ' "errors": [\n' +
    ' {\n' +
    ' "category": "AUTHENTICATION_ERROR",\n' +
    ' "code": "UNAUTHORIZED",\n' +
    ' "detail": "This request could not be authorized."\n' +
    ' }\n' +
    ' ]\n' +
    '}',
  result: [Object: null prototype] { errors: [[Object: null prototype] ] },
  errors: [
    [Object: null prototype] {
      category: 'AUTHENTICATION_ERROR',
      code: 'UNAUTHORIZED',
      detail: 'This request could not be authorized.'
    }
  ]
}

```

The application and account were created in the US, but I am traveling Internationally for a few weeks. I wondered if this was a location issue, so I accessed an Atlanta VPN node through NordVPN and got the same issue.

Please advise.

---

<div class="post-metadata">

**Author:** ![Lance-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/lance-square/32/2704_2.png) [@Lance-Square](https://developer.squareup.com/forums/u/Lance-Square)\
**Post date:** [July 28, 2023, 12:43am UTC](https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110/2 "2023-07-28T00:43:37Z")

</div>

Hi @xocrates ,  
I was also able to reproduce a similar 401 in my browser when I mistakenly used my production API credentials in my .env instead of my sandbox API credentials.

Can you confirm, what is your sandbox application id? You can get this from [Developer Dashboard](https://developer.squareup.com/apps) → Open your application → Ensure you are toggled to sandbox on the top middle, and copy the sandbox API credentials.  
And please DO NOT share your access token, just the sandbox application id.

---

<div class="post-metadata">

**Author:** ![xocrates](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/xocrates/32/2136_2.png) [@xocrates](https://developer.squareup.com/forums/u/xocrates)\
**Post date:** [July 28, 2023, 3:24am UTC](https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110/3 "2023-07-28T03:24:10Z")

</div>

Hey @Lance-Square ,

For sure:  
sandbox-sq0idb-t-AwkofzncmD1QHWdcoT2g

And in my .env:

 ![Screenshot 2023-07-27 at 10.34.07 PM](https://global.discourse-cdn.com/square/original/2X/f/f7f3ec31fc76a5f02facb3339b28ec0c6d458efe.png)

---

<div class="post-metadata">

**Author:** ![xocrates](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/xocrates/32/2136_2.png) [@xocrates](https://developer.squareup.com/forums/u/xocrates)\
**Post date:** [July 28, 2023, 7:18pm UTC](https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110/4 "2023-07-28T19:18:08Z")

</div>

Hi @Lance-Square,

Any thoughts on the above? If you look closely at the terminal error I provided, there are two lines that stand out to me:

```auto
    headers: {
      authorization: 'Bearer undefined',

```

and

```auto
    'x-sq-envoy-safe-auth-decision': 'UNAUTHORIZED',
    'x-sq-region': 'sjc2b',
    'x-xss-protection': '1; mode=block',

```

Let me know what you think, thanks

---

<div class="post-metadata">

**Author:** ![Horticode](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@Horticode](https://developer.squareup.com/forums/u/Horticode)\
**Post date:** [July 28, 2023, 10:47pm UTC](https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110/5 "2023-07-28T22:47:39Z")

</div>

> [@xocrates](#):
>
> `authorization: 'Bearer undefined',`

did you set your env access token?  
do not share it. Are you working on an app for 3rd party use? or personal?  
If only for personal use you do not have to deal with Oauth, and as such the application\_id does not even need to be sent.  
the Authorization: Bearer \<access\_token\> is all that is needed.

---

<div class="post-metadata">

**Author:** ![xocrates](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/xocrates/32/2136_2.png) [@xocrates](https://developer.squareup.com/forums/u/xocrates)\
**Post date:** [July 30, 2023, 2:28am UTC](https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110/6 "2023-07-30T02:28:06Z")

</div>

I removed the `SQUARE_LOCATION_ID` key from my `.env`, which now works. I am able to continue messing around with the example build. Thank you. Any reason why this resolved my issue?

---

<div class="post-metadata">

**Author:** ![josh-square](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@josh-square](https://developer.squareup.com/forums/u/josh-square)\
**Post date:** [July 31, 2023, 8:37pm UTC](https://developer.squareup.com/forums/t/response-status-code-was-not-ok-401/10110/7 "2023-07-31T20:37:52Z")

</div>

Hey @xocrates, it’s possible that the Location ID had an invalid value that was causing the access token to fail to set. In any case, happy to hear you’re able to work with the example!
