Get data from response headers
Options
Evgeny Sporykhin
Member ✭
Hi all! I try to upload video on youtube and use youtube data API
I send POST request to API and receive the response, but the data which i need is in response headers
How i can get access to response headers? Try $http_headers, but it isn't return the right data
I send POST request to API and receive the response, but the data which i need is in response headers
How i can get access to response headers? Try $http_headers, but it isn't return the right data
Comments
-
Hi ,
The return from the API request is an object with all relavent information.
var ret = API_Request
the response headers would be inside ret.response.headers - see screenshot - https://mrkr.io/s/62865535d368286d46f30e9a/0
the environment variable $http_headers are the request headers sent to Xano, not the API request being run inside your function stack. -
yeah, but how i can get, for example, content-length in header?
-
I think to accomplish your goal you want to apply the "get" filter to ret.headers, and pass the path of "content-length"
Correction: see 's correct and detailed description of working with the array rather than object mapping below. -
close - ret.response.headers is an array of key/value pairs in string form
$http_headers is an object where the key of each object is the header key.
You need to do a bit more work for ret.response.headers
You can use Data Manipulation - Arrays - Array.findFirstElement
Pass in the value content-length:
You can assign that to a variable called header.
Then you have the entire header in a variable. To extract the number from that, you would want to do the following
var:length = var:header|split(":")|last|trim -
thanks! i will try that
-
thanks! i tried your first solution and it didnt work)
-
Here is how I managed to access headers, through a Lambda.
const headers = $env.$http_headers console.log($env, headers); return headers;
-
And then, how do you test this? Because reading the Authentication header is one thing, prefilling it for in-editor testing is another…
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