Unable to read header value for a request that is sent in Pre-req

Hey @baljindernohra, welcome!

This can certainly seem tricky since you’re using pm.sendRequest to send your request instead of as a “proper” postman request.

You are going to have to use the response variable from your callback instead of pm.response to get what you want. Take this example of calling the postman echo API:

pm.sendRequest({
    url: 'https://postman-echo.com/post',
    method: 'POST'
}, function(err, res){
    const location = res.headers.find(h => h.key == 'Location');
    pm.environment.set('location', location);
});

So you can see that res is my response variable in the callback. You can get to the headers from there.