Print Response Header Value in Tests


I am new to Postman, I want to print a response header value, in tests, if it exists.
For example if there is a RequstID header key and it has a value, I need a test to Say PASS when RequestID exists and prints its value in test result after PASS

Hey @singhsharad :wave:

Welcome to the Postman Community! :postman:

You can use this to print all headers to the Postman console:

let headers = pm.response.headers.all();

Iโ€™m not sure what exactly you would like your test to look like or check for but hereโ€™s an example of using a specific header:

let headers = pm.response.headers.all();

let filteredHeader = headers.filter(header => header.key === "Date");

pm.test(`Response has the Date header - Header Value: ${filteredHeader[0].value}`, function () {

Happy to edit the solution if you provide a few more details.

Hi Danny,

Appreciate your time for providing the solution, it works for me and fits my requirement.

Thanks Again !!!


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.