Setting headers for entire collection/folder

Can you open Postman Console and check?
View > Show Postman Console or you can click the following icon:
image

Now, once you send the request you’ll see what all headers are actually going through along with your request like so:

Also,
The headers that are dynamically generated through the pre-request script will not be shown up as a part of the code that is generated.

1 Like

YAHOO!
It worked guys.

Maybe I got mixed something earlier.

Thanks a lot.
Super cool support.

1 Like

Unfortunately still does not work for me (Postman 6.7.1, linux-4.15.0-48-generic on x64 / Ubuntu 18.04). At the level of pre-request script the additional header is successfully added to the headers collection, however it is somehow lost in the final, sent request. Which would be actually coherent with what the documentation says about request object:

This object is read-only. Changing properties of this object will have no effect.

Has something changed in the implementation recently?

Hey @carivaldi,

I can see from your message that you have 6.7.1.

We’re going through the documentation and updating this to reflect the current functionality - This will eventually be shown here:

1 Like

@dannydainton thanks for the quick response!
I can see the Ubuntu repository is a a little bit behind - I’ll try again when 7.0.9 is there.

Which method of installation of you using? If you’re using snap - You might need to use the candidate channel.

sudo snap switch --channel=candidate postman
sudo snap refresh postman

There is still 7.0.7 in the candidate channel - I switched to it and since it is not really a show stopper for me, I’ll wait patiently until 7.0.9 comes :slight_smile:

Thanks for help!

Hey @carivaldi,

The snap candidate channel has been updated to 7.1.1 - If you wanted to give the headers another go. :slight_smile:

Thank you so match!!

hi guys,

I’m trying to add a header for every request under a folder. The pre-request scripts seem to be my best bet, however, I can’t get it to work with variables. It fails with bad syntax no matter which way I code it and I can’t find any documentation or thread on it.

Essentially, I need to read the values set in the environment variable since the header name and value depends on which environment you’re sending the request from.

So something like this:

pm.request.headers.add( { key: {{headerName}}, value: {{apiKey}} } );

That’s not valid syntax though. So how can I achieve this?

thanks! :slight_smile:

Hey @matheusGuimaraes

Have you tried this:

pm.request.headers.add( { key: pm.environment.get('headerName'), value: pm.environment.get('apiKey') } );

Thank you, Danny!

I actually had tried that and it had failed with a syntax error, but I just tried again blindly with copy/paste from your reply and it worked so I must have missed a bracket or something and assumed it was lack of support for variables.

thank you so much and sorry for the time waste :slight_smile:

You’re welcome. Glad to see you got it working. Don’t worry, it’s never a waste of anyones time. :trophy:

1 Like

Hi,

Thanks to this post I manage to set a default header to a collection.


That’s great but, while it works and the request is sent correctly, it should be considered a workaround (or a bug to be fixed) because headers set this way are:

What do you think?

Hey @ohjimijimijimi,

Welcome to the community! :trophy:

I would expect to see that header in the Postman Console under the Request Headers and not in the request list that you would see.

Also, I wouldn’t expect to see it in the code snippet as that’s not taking anything in the Pre-request Script as that would of been actioned at runtime.

It looks like your app is slightly behind the current version as the temp headers section has been removed / changed now. :slight_smile:

Hey @dannydainton,

thanks for the prompt response. You’re right, app was old, now is updated.

This is what I’m seeing in the temp headers section

I agree with you when you say

I wouldn’t expect to see it in the code snippet as that’s not taking anything in the Pre-request Script as that would of been actioned at runtime.

Using the pre-script to add headers is maybe not the right approach, but to me it seems also the only one atm.

Is there any plan to add default headers per collection?

1 Like

There is a similar open feature request for this on our Github Tracker, you could upvote this so we’re aware more users would like to see this in the product :slight_smile:

1 Like

The problem I faced with the selected answer is that it doesn’t copy/paste automatically the pre-request scripts in a new request even if you duplicate a request.
The instructions in “Inheriting Auth” worked nicely though https://learning.postman.com/docs/sending-requests/authorization/#inheriting-auth. I set Authorization to API Key, select a custom header key and set the value to an env variable authToken and choose “Inherit from Parent” for first request and when I duplicate this, the auth works out-of-the-box for new request. And if auth token changes, just update the env variable authToken and it should reflect for all requests without doing much.