Basics:
I have never coded in postman and I may not refer to the correct nomenclature or naming. If so, I am sorry, but I am happy to learn
Scope:
I am calling a server to get various values from the server.
it may be login tokens, IDs, carts etc.
I also have several postman environments with a copy of each environment but with a change in the server domain name only. I would like to understand how I can simplify this mess of environments.
Issue:
This is an example of a script I have an issue with. This is applicable to other server response calls also.
Question:
1.How can I now pick the token from the response from the server? OR any of the other varibles?
2. how should I get this to work? Please share example code as I have read through some of the postman areas, but I do not have enough coding knowledge to understand it.
Code:
This is a a call to get a login token to an ecommerce site
You would first need to get all the response using:
const resp = pm.response.json();
From here you will be able to get specific parts of the data that you have saved to the local variable.
As your response is an array and you want to access the first object in the array, you need to use [0] if you didn’t use that, the stored value would be undefined.
Will this stored as a Collection variable, you can use this in the URL by using the {{customer_token}} variable name.
This are all quite basic workflows in Postman and I would highly recommend working through the training in these Collections, to get more familiar with these fundamental techniques.
That was setting a Collection level variable in the script, I know that’s not the Collection Variables section as you cannot change the type of those.
If you open your Collection in a new tab, there is a Variables sections within that.
This is all covered in those training course, to avoid answering a series of similar questions, I would highly suggest you work through those courses or at the very least, take a look at our documentation.