Google News
logo
Postman - Interview Questions
How can you set headers for all the requests that are in a particular Postman collection?
Postman collections allow adding pre-request scripts at both the collection as well as individual request level. To add any script that applies to all the requests that are present in the collection, we will need to add a pre-request script at the collection level.
 
Please follow the below steps to add a collection level pre-request script for adding a header to all the requests.
 
a) Open collection options by right-clicking the collection and navigate the pre-request script tab.
b) Now add the below script for adding a request header for all the requests.
pm.request.headers.add({
    key: 'TestHeader',
    value: 'testValue'
});
c) Click Update to save the collection level pre-request script.
 
d) Now execute any request in the collection (directly or through collection runner) and view the request details in the Postman console debugger to validate if the pre-request script is working fine and adding the specified header.

Postman
Advertisement