Whenever I am adding this documentation to Postman, it changes my global variable /{{tenantName}} to an object like /:tenantName.
Does anybody have solution for it?
Related
postman.setEnvironmentVariable("documentNumRequest", pm.environment.get(documentNumUserPF));
Postman noob here. I have this POST call and I want to put the value of "documentNumUserPF" in "documentNumRequest", but i couldn't use the environment variables inside the code. Any tips?
Error:
ReferenceError: documentNumUserPF is not defined
postman.setEnvironmentVariable("documentNumRequest", pm.environment.get("documentNumUserPF"));
you are telling to get variable with name documentNumRequest so enclose it with qoutes
https://github.com/postmanlabs/postman-app-support/issues/3648
postman keyword will be deprecated in future , so move to new pm api and use it more
pm.environment.set("documentNumRequest", pm.environment.get("documentNumUserPF"));
I have variable "TOKEN" in my collection scope. I try to set the value using Tests scripts when do a request. But the variable not changed.
So, I try to use environment scope variable. And It works.
Why It's doesn't work when in collection scope? I had read about postman variable scope here and understand it well.
Here're some screenshots:
1. First, I call login endpoint.
Below is the console result. Nothing wrong.
Until I try to get all users endpoint that required token in request header. The status is 401 because the token is null. If the token is not null, then it will return 200:
It's gracefully working when I add "TOKEN" variable to environment. Switch to No Environment again will result 401 status code:
This may be new since this question was posted, but for anyone else
finding this, you can set collection variables using:
pm.collectionVariables.set(key, value)
See:
https://learning.postman.com/docs/sending-requests/variables/#defining-variables-in-scripts
You can now use:
pm.collectionVariables.set("variable_key", "variable_value");
In my original answer in June 2019, I wrote that collection variables are not editable through scripts, and can only be changed manually. As noted, this is no longer the case. . . .*
Turn off Automatic persist variable values from postman settings.
image
It seems you can only set env variables when some environment is selected: https://learning.postman.com/docs/postman/scripts/postman-sandbox/#environment-and-global-variables
How to pass multiple variables as Header Request in the postman?
You can do something like this as follows-
Create environment variables in your postman. If you dont know how
to create environment variables the use this link.
Use the variables in your Header like this-
Benefit of the environment variables is you can use multiple variables and its values and it optimze your work efforts.
Hope this helps.
When I add environment variables I can use them in my post body with {{varName}}. But this does not work for collection variables (Collection > edit > Variables tab)
With the settings as shown above, if I add {{firstName}} to my body it does not work. How can I access these collection variables in my posts?
Currently if I try to post postman will just hang for a while then give this error
Error: Script execution timed out.↵ at
ContextifyScript.Script.runInContext (vm.js:53:29)
If I use an environment variable or just type in a value it works fine.
Also, you need to make sure to save the request to the belonging collection before you can use it!
It turns out {{varName}} does work. The problem was in my pre-request script. The API I was connecting to requires a checksum on the body so it pre-processes the variables in the body, but it was not setup to handle collection variables. This was causing postman to fail. User error.
I have the following setup:
A global variable api_address defined as http://apiproduction.mydomain.com.
A collection variable route_address defined as users/profiles for each collection.
Right now my query look like: {{api_address}}/{{route_address}}/004ba492-d021-40fe-ba23-f1d366036af4 if i want to get the resource.
So my question is... Could you include in a collection variable a global one?
Example: {{route_address}} could be defined as {{api_address}}/users/profiles.
Yes you can do this! But you have to do it with pre-request scripts.
Edit your selection and go to the pre-request script tab.
Add something like the following:
let api_address = pm.globals.get("api_address");
pm.variables.set("route_address", `${api_address}/users/profile`);
That should give you your "route_address" that you are looking to variablize.
You can probably to the pm.globals.get inline on your set, but I'm old school and think it's cleaner and easier to read if you throw it into a local variable first.