Postman: add a given header to all requests in the given collection or collection-level header
Asked Answered
R

1

6

My question: Postman: add a given header to all requests in the given collection or collection-level header.

Details (like screenshots): I have “x-apikey” header & a bunch of requests in the collection without this specific header. How can I avoid manual work of adding header one by one to each request? Anyone has an existing solution, please?

How I found the problem: Imported OpenAPI spec & it does not contain the needed header. Hence, need to add to each request.

Rewarding answered 7/9, 2021 at 11:23 Comment(0)
A
19

You should be able to do this in your Pre-request Scripts at the Collection level.

pm.request.headers.add({key: 'x-apikey', value: 'token_value' })
Arlinearlington answered 7/9, 2021 at 12:10 Comment(3)
It has to appear in a header of every collection request, hasn't it?Jordonjorey
It's absurd that they didn't make this kind functionality available in the GUI. Having specific headers carry over to all requests in a given collection seems like obvious functionality to me. Who is steering the ship over at Postman?? This doesn't affect me too much as I am a developer, but I know many testers who aren't that technical and rely on GUIs to do their job.Theatricals
I'm sure those testers have the capability to search for something on SO or read some documentation. Being "technical" doesn't really matter. If you feel that you'd like to raise this as a feature request, that would be very welcomed. 🙏🏻Arlinearlington

© 2022 - 2024 — McMap. All rights reserved.