# Generate header based on body for a collection of requests

**URL:** <https://community.postman.com/t/generate-header-based-on-body-for-a-collection-of-requests/24532>\
**Category:** Help Hub\
**Tags:** collections\
**Created:** [June 4, 2021, 7:27pm UTC](https://community.postman.com/t/generate-header-based-on-body-for-a-collection-of-requests/24532 "2021-06-04T19:27:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flight-architect-935](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@flight-architect-935](https://community.postman.com/u/flight-architect-935)\
**Post date:** [June 4, 2021, 7:27pm UTC](https://community.postman.com/t/generate-header-based-on-body-for-a-collection-of-requests/24532/1 "2021-06-04T19:27:04Z")

</div>

Hi everyone!

I have a service that checks if a dynamically generated header has a certain value.

For sake of simplicity let’s suppose this header is the concatenation of URL and body. It should be feasible to do so for a single request using variables.

How can I extend this behavior to all the requests of a collection?

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [June 7, 2021, 6:56am UTC](https://community.postman.com/t/generate-header-based-on-body-for-a-collection-of-requests/24532/2 "2021-06-07T06:56:38Z")

</div>

Hey @flight-architect-935 👋 Welcome to the Postman Community 🎉

If I understand your query correctly, you want to apply the same set of script for each request in a collection, is that correct?  
If so, you can add pre-request script for a collection as below to add `pm.request.headers.add()` method to add a custom header to each request:

 ![Screen Shot 2021-06-07 at 4.53.46 pm](https://us1.discourse-cdn.com/getpostman/original/3X/2/1/2148f6d657cad9fda97de528ac3830b8c824eb23.png)

Hope this helps! Let me know if you have further questions 😃

---

<div class="post-metadata">

**Author:** ![flight-architect-935](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@flight-architect-935](https://community.postman.com/u/flight-architect-935)\
**Post date:** [June 8, 2021, 10:11am UTC](https://community.postman.com/t/generate-header-based-on-body-for-a-collection-of-requests/24532/3 "2021-06-08T10:11:48Z")

</div>

Thank you! That’s indeed what I needed 🙂
