External API - 401 error - Twitter API - Works on Postman
![Carlos](https://us.v-cdn.net/6037124/uploads/userpics/P8CEOAI3SFPD/nL13Q96FNH3X2.jpg)
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
}
}
Best Answer
-
Thanks Ray for passing by,
I did try adding “Authorization: Bearer” to my token variable and still didn't work (I know is not showing in the request I've pasted here). Also hardcoded it directly in the request and nothing.
Not sure what it was tbh, in part also because my QA process was a mess… not my forte specially when tired, it might be that I had it misspelled or something similar
Answers
-
Solved.
I've generated the cURL from Postman itself and that did the trick, is working now.
However, I'm comparing both requests and honestly don't see the difference.
Anyway, if your external API works on Postman but not in Xano go to
code
, right side menu, belowSend
, copy the cURL and import it into XanoKeep pushing!
-
That's great! It seems clear now that your problem was that the original had just the token by itself as a header, without the “Authorization: Bearer” text that needed to precede it.
Clever to build it in Postman and then curl-copy it to Xano - will put that technique in my toolbox for the future!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback