'How to set environment variable in Postman depending on other values in response?
Using GET request, I have the following response:
[
{
"id": "ID_1",
"name": "",
"color": "orange"
},
{
"id": "ID_2",
"name": "",
"color": "yellow"
},
{
"id": "ID_3",
"name": "",
"color": "red"
},
....
]
I need to set each ID as a environment variable. At first I did it using:
pm.environment.set("Orange_ID", jsonData[0].id);
pm.environment.set("Yellow_ID", jsonData[1].id);
pm.environment.set("Red_ID", jsonData[2].id);
And it works. But then I noticed that whenever I send a request, the order in the response is not the same. For example, the first is yellow, the second red, and so on. So I need to change variables.
Could you please help me how I can
set "Orange_ID" variable where color = orange
set "Yellow_ID" variable where color = yellow
set "Red_ID" variable where color = red
Thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
