Hi all
New to postman and the use of json (arrays).
My question:
I want to use the json array output of a GET call and use this into a new GET request. The second output should be used into a POST call. In detail:
1st GET call:
The first call will result in a json array of id’s.
Example:
{
“values”: [
{
“id”: “d935b234-96dc-4ac0-b1b7-cde69d0bab75”,
“name”: “Test1”
},
{
“id”: “5ec38828-ab5c-4a86-97e3-c048f82aad6b”,
“name”: “Test2”
},
{
“id”: “38d1266a-3e2f-4c27-b605-1c29a42c0298”,
“name”: “Test3”
}
]
}
2nd GET call:
With the ouput of the first call I would like to loop over the id’s and use them into the 2nd call. This call would get the properties for each id. The output of this call should contain the info from the field { “name” , so remove all prior to the name and POST this into the 3rd call.
Example:
{
“metadata”: {
“configurationVersions”: [
7
],
“clusterVersion”: “1.222.86.20210802-200423”
},
“id”: “d935b234-96dc-4ac0-b1b7-cde69d0bab75”,
“name”: “Test1”,
“description”: null,
“rules”: [
{
“type”: “SERVICE”,
“enabled”: true,
“valueFormat”: null,
“propagationTypes”: [
“SERVICE_TO_PROCESS_GROUP_LIKE”
],
“conditions”: [
{
“key”: {
“attribute”: “PROCESS_GROUP_NAME”,
“type”: “STATIC”
},
“comparisonInfo”: {
“type”: “STRING”,
“operator”: “CONTAINS”,
“value”: “mendix”,
“negate”: false,
“caseSensitive”: false
}
}
]
},
{
“type”: “APPLICATION”,
“enabled”: true,
“valueFormat”: null,
“propagationTypes”: ,
“conditions”: [
{
“key”: {
“attribute”: “WEB_APPLICATION_NAME”,
“type”: “STATIC”
},
“comparisonInfo”: {
“type”: “STRING”,
“operator”: “CONTAINS”,
“value”: “test.test.test.test”,
“negate”: false,
“caseSensitive”: false
}
}
]
}
],
“entitySelectorBasedRules”:
}
I’ve already tried:
I tried in my 1st GET call in the test section to create a collection variable. The below code did work and created the variable autotag_id
var resp = pm.response.json();
autotag_id = ;
for (var i=0; i<resp.values.length; i++)
{
autotag_id.push(${resp.values[i].id}
);
pm.collectionVariables.set(‘autotag_id’, (autotag_id));
}
Result:
How can I use this variable and loop all the values in the 2nd GET call, strip the info and use it into the 3rd call.?