Console Response Header Value, How to Retrieve?

My question: The API, I am working with has been coded in a way that the TOKEN which I want does not appears in the body or headers section. Instead it comes in console under Response Header. How can I get that value?

Details (like screenshots):

I’ve already tried: I have looked around a lot of things but couldnt find any solution. Would be really glad if anyone can assist in that.

All I want is to fetch the sssToken store it and use in other headers.

Hey @univashu

You can use this to get the full value of the header and then split it on the = character:

console.log(pm.response.headers.get('Location').split('='));

From that you will see an array of values and it will be the last one :thinking:

I tried that but its coming as undefined.

Just to give you more clear picture please refer the below screenshots.


The command you shared fetches the value from header which is in response but I need to fetch value from console header. I hope I am making sense.

It looks like that original request is redirected (302 status) to a different URL which contains the Location header. That information wasn’t part of the original questions and missing the the cropped image.

As that code snippet is in the original request, the Location header isn’t part of that response - that’s why it’s undefined

Yes, I am sorry I missed that part. But is there any way I can fetch that particular value?

This might work but I’m not confident :confused:

If you go to settings and disable “Automatically follow redirects”, then add this to the Tests:

const querystring = require('querystring');

let params = pm.response.headers.get('Location').split('?')

console.log(querystring.parse(`${_.last(params)}`).sssToken)

It’s probably not what you need as it wouldn’t complete the flow you need - I’m unsure have to get the headers from a redirected URL in an efficient way :frowning:

Were you able to retrieve value from console, do you mind share your solution?

Not really from console header but turning off Automatic redirect helped me.
As due to that I was able to pick the value from initail request.

Thank you, I will try that way.