External API - 401 error - Twitter API - Works on Postman

Answered

Hi everybody,

I'm trying to do a basic call to Twitter

  • API GET /2/users/by/username/:username
  • I've copied the cURL into my function
  • Added my Twitter Bearer token as an Environment variable
  • The Beare token is pushed into the Headers array.

I always get a 401 back. That same request in Postman works fine, using exactly the same Bearer token.

I've been blindly trying things for a while, can't see what I'm missing. Help please 🙏🏼

That's the look of my function:

— The response —

{

request: {

url: https://api.twitter.com/2/users/by/username/TwitterDev,

method: GET,

headers: [

GET /2/users/by/username/TwitterDev HTTP/2,

Host: api.twitter.com,

accept-encoding: gzip, deflate,

content-type: application/json,

accept: application/json

],

params: []

},

response: {

headers: [

HTTP/2 401,

perf: 7626143928,

content-type: application/problem+json,

cache-control: no-cache, no-store, max-age=0,

content-length: 99,

x-transaction-id: f6cf6db836763e1f,

x-response-time: 1,

x-connection-hash: 1b230d0571be9d81f61b891f01d5cf8e45fc4a3575c3421f54695d23b2b54217,

date: Sat, 25 Feb 2023 09:22:19 GMT,

server: tsa_b

],

result: {

title: Unauthorized,

type: about:blank,

status: 401,

detail: Unauthorized

},

status: 401

}

}

3 replies