Setting headers for entire collection/folder

Hey @lutaiphong

Not really sure what you mean by it didn’t work , it’s a little bit vague. :grin:

Are you able to expand on that more with some details about what you tried to do and where you added that code.

A screenshot would be a big help too :grin:

Sure Danny.

Here I just try to add the header header_name with value header_value to the request.

Then just submit it.
However I looked at the generated code, there is no header_name.

And on the API, I received nothing either.

Can you check the response headers tab, in the app, rather than the generated code snippet for the request please?

You mean this, right?

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

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

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

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


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: