Hey @seitzcasey,
You could also use variables to store the authentication data, so that in each request do you not have to repeat the username, password. You could read from the variable using pm.variables.get("variable_key")
I was hoping there was a way without having to do anything other that create the request inside my collection, set the endpoint and have it work. Is that possible?
So, just to be clear, you want to define a “Pre-Request” script within the collection, and not create actual Postman Request objects within the collection (as in a Request in the UI?)
If thats the case, then the way you’d like to achieve that wouldn’t be possible. You need at least one request in the collection to run an actual request.
If this is not what you are asking, please clarify a bit more, and I’ll be glad to provide more help
No thats not what I meant. I want to avoid adding {{body}} each time I create a new request in postman. I want the collection level pre-request script to populate the request body without any extra action from the user.
The request doesn’t seem to be receiving the data. When I hit the postman echo endpoint, there are no args listed. But if I add them manually in the body tab, they do show.
You cannot change the request body in that way using pm.request.body.update - Although it might log that to the console, it won’t change the main body of the request that’s sent.
In Pre-request script, call a function defined in the Collection pre-request
//Formats the correct EHR_STATUS object template to adjust for differences between Better and ehrBase
pm.variables.set('ehrStatusTemplate',utils.formatEhrStatusTemplate(pm))
and the function in the Collection pre-request script is
Hah - doing this helped me fix an annoying issue that you although pm is in scope for a variable.get(), unless you explicitly pass pm into the function, you cannot do a .set(), or at least it is not persisted.
Hi have a question, in the result from my system the file contains more segments, for example
{
“load”: {
“company_code”: “247741”,
“facility_code”: “CICEMX2”,
“load_nbr”: “CSTR00000124”}
}
in this case only required 3 values: “company_code”: ,
“facility_code”: y “load_nbr”: