Weird Node Auth issue with Threads API (Sandbox)

I looked through this forum, but can’t figure out what’s going on. This is in the Nylas sandbox environment.

If I run this command from the command line, it works great:

  curl --request GET \
  --url 'https://api.us.nylas.com/v3/grants/GRANT_ID/threads?limit=1' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer API_KEY' \
  --header 'Content-Type: application/json'   

However, when I run it from node.js like this (version 7.5.2):

const client = new Nylas({
  apiKey: 'API_KEY', 
  apiUri: 'https://api.us.nylas.com', 
});

// ...

var threads = await client.threads.list({
  'GRANT_ID',
  queryParams: {
    limit: 5,
  },
});

I get this error:

ENylasApiError: Bearer token invalid
    at APIClient.sendRequest (/workspace/node_modules/nylas/lib/cjs/apiClient.js:91:33)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async APIClient.request (/workspace/node_modules/nylas/lib/cjs/apiClient.js:147:26)
    at async Threads.fetchList (/workspace/node_modules/nylas/lib/cjs/resources/resource.js:17:21)
    at async Threads.listIterator (/workspace/node_modules/nylas/lib/cjs/resources/resource.js:48:23)
    at async Object.fetchRecentThreads (/workspace/utils/my_nylas.js:51:19)
    at async /workspace/index.js:161:17 {
  type: 'token.unauthorized_access',
  requestId: '1727746351-181ae032-bf66-4556-9f63-688a4b3258ae',
  providerError: undefined,
  statusCode: 401
}

I looked at the common issues (US vs EU) and verified GRANT_ID and API_KEY are identical in both scenarios. I don’t understand why this would happen. Could this be a sandbox issue…?

Also, note, I have done successful oath with the client so the API key used in node is correct.

Hello @oskar that seems weird :thinking: Let me take a look at will come back to you

I figured it out. Your documentation is incorrect. I looked here:

And it says:

await nylas.threads.list({
      identifier,
      queryParams: {
        limit: 5,
      }
    })

but it should be:

await nylas.threads.list({
      identifier: identifier,
      queryParams: {
        limit: 5,
      }
    })

The key identifier was missing :slight_smile:

Oh! You’re right :sweat_smile: Those things are hard to find sometimes…will submit a PR to fix it right now :wink: