My question:
Hi everybody,
I need your help.
By calling a GET API through Postman, I get an array of objects like this (it’s just an anonymized example, the actual objects are much longer):
[
{
“id”: “123456789”,
“name”: “Paul”,
“surname”: “Green”,
“country”: “Germany”
},
{
“id”: “987654321”,
“name”: “Mary”,
“surname”: “Jane”,
“country”: “France”
},
{
“id”: “192837465”,
“name”: “John”,
“surname”: “White”,
“country”: “Spain”
}
]
What I need is to:
- store the whole array of objects into a collection variable (say, “wholeResponse”);
- create a pre-request script in the subsequent POST call, so that it will pass a refined array of objects (containing only, say, “id” and “country”).
In the next POST call, the request body should look like this:
[
{
“id”: “123456789”,
“country”: “Germany”
},
{
“id”: “987654321”,
“country”: “France”
},
{
“id”: “192837465”,
“country”: “Spain”
}
]
I’ve already tried:
I’ve managed to accomplish step 1, i.e. to tailor a test script (concurrent with the GET) which stores the whole array of objects into a variable:
let responseData = pm.response.json();
pm.collectionVariables.set(‘wholeResponse’,JSON.stringify(responseData));
But after doing this, I have no idea how to refine the array I have stored for subsequent use.
Any help from your side would be highly appreciated, thank you in advance!