The following is a basic sendRequest to Postman Echo.
The screenshot clearly shows the key as “header” when you console log the response, but when you console log the Object keys, its shows “headers” which does actually work.
Thank you for responding, but even with the headers key, it is not possible to get any of the array elements. As for the res.json() option, in this case I only get the response body without headers.
I’ve had a look and you are correct. You can’t target any of the headers that way.
console.log(res);
console.log(typeof(res.headers));
console.log(res.headers);
pm.test('headers should be an array', () => {
pm.expect(res.headers).to.be.an('array').that.is.not.empty;
});
I think I’ve seen this before. It’s technically not an array, its a list which is why you need to parse the response.
I guess whether the headers exist once you parse a response, will be down to the API specification.
On a normal request, you can use the pm.response method, but I’m not sure if there is an equivalent for sendRequest().