How to set global request header information in Postman
Tags: postman
Published: 2024-02-28 14:06:18

[Postman](https://zguyun.com/blog/what-is-postman/) is a powerful API development tool that not only allows users to send requests and test APIs but also enables them to set global request header information to ensure that each request contains the same header information every time it is sent. In this article, we will detail how to set global request header information in [Postman](https://zguyun.com/blog/how-to-use-postman/).


## What is Global Request Header Information?
In HTTP requests, header information contains important details about the request and response. Sometimes, we want to include the same header information with every request, and setting global request header information is useful for this purpose. By setting global request header information, we can ensure that each request includes pre-defined header fields and their corresponding values.

## Steps to Set Global Request Headers
### 1.Open Postman and select or create a collection.

Make sure you have opened the [Postman](https://zguyun.com/blog/comprehensive-guide-to-implementing-automated-testing-in-postman/) application. Then, in the left sidebar, select or create a collection where you want to add global request header information to organize your requests. Left-click on the chosen collection or click on the three dots next to the collection name and select the "Edit" option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr712guxdteu7kp0qaje.png)


### 2.Add Global Request Header Information

In the collection settings page, you will see an option named "Authorization". Under this option, you can add some global request header information.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8a9a89ao0yjsqy4ijvo.png)



For example, if you have a login interface, and you have set the token credential of the interface via Tests script into an environment variable, now you want to apply this token credential to all interfaces under this collection. You can choose the Type as Bearer Token here and reference the token value from the environment variable using **`{{}}`**. This way, when requests are made by interfaces under the collection, they will automatically carry this token credential.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8l7grz6f6knio6c9j2mu.png)



If you want to set other types of request headers, you can also click on the "Pre-request Scripts" tab to enter the request script page and write a script to add headers. In the request script page, you can write JavaScript code to add request headers. Here is an example code:

```javascript
// Set global request header
pm.request.headers.add({
    key: 'Authorization',
    value: 'Bearer your_access_token_here'
});

// Add other request headers
pm.request.headers.add({
    key: 'Content-Type',
    value: 'application/json'
});
```

Please note that you can modify the request header fields and values according to your needs in the above code.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z5fpbcmdsguk6srr2ide.png)


### 3.Verify Global Request Header Settings

Now that you have successfully set the global request header information, to ensure that your requests are using these headers correctly, you can open any request and verify if they are included under the headers section. You can check by clicking on the request path in the Console.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjqjh1qoyn2kuxz2ma2u.png)



## Conclusion

Key steps in setting global request header information using [Postman](https://zguyun.com/blog/what-is-postman/) include adding the required header information to the collection settings page, ensuring the appropriate type and value are selected, adding additional request headers if necessary through JavaScript scripts, and finally verifying that the settings have taken effect.


Reference：

-   [Postman Documentation - Setting Headers](https://learning.postman.com/docs/sending-requests/requests/?ref=zguyun.com#headers)

Learn more:

-   [How to send requests in a loop in Postman](https://zguyun.com/blog/how-to-send-requests-in-a-loop-in-postman/)
-   [Comprehensive Guide to Implementing Automated Testing in Postman: A Deep Dive](https://zguyun.com/blog/comprehensive-guide-to-implementing-automated-testing-in-postman/)
- [How to add certificate in Postman?](https://zguyun.com/blog/how-to-add-certificate-in-postman/)
- [How to convert timestamps in Postman?](https://zguyun.com/blog/how-to-convert-timestamps-in-postman/)
- [How to import a JSON file into Postman？](https://zguyun.com/blog/how-to-import-a-json-file-into-postman/)