Hey @lutaiphong
Not really sure what you mean by it didnāt work , itās a little bit vague.
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
Hey @lutaiphong
Not really sure what you mean by it didnāt work , itās a little bit vague.
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
Then just submit it.
However I looked at the generated code, there is no header_name.
Can you check the response headers
tab, in the app, rather than the generated code snippet for the request please?
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:
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.
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:
https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/#pmrequest
@danny-dainton 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
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.
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!
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
Youāre welcome. Glad to see you got it working. Donāt worry, itās never a waste of anyones time.
Hi,
Thanks to this post I manage to set a default header to a collection.
What do you think?
Hey @ohjimijimijimi,
Welcome to the community!
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.