Reading Multiple Response Bodies With Non Key/Value Pair

I have an end point that returns multiple json structure:
{
id: 1
name: name1
}

{
id: [n]
name: name[n]
}

/root/end_point/

Using the same end point, I place all ids into an env. array to pass to a second request as follows:

/root/end_point/{{id}}

The problem I have is this can’t be a key/value pair. Any help or direction would be appreciated.

Thanks in advance

If what you got back was an array it would be easy.

Is the response valid JSON? Check here - valid JSON?

At this point, i can read one record (last one) in the second request from this statement in the first request:
let jsonData = JSON.parse(responseBody);
var api = new Array();
for (var x=0; x<jsonData.values.length; x++) {
api = jsonData.values.id;
}
pm.environment.set(“request_env”, JSON.stringify(api, null, 2));

In ‘pre-request’ in the second request, i can pull all ids with:
let api_req = JSON.parse(pm.environment.get(“request_env”));
for (var x=0; x<api_req.length; x++) {
pm.environment.set(“MyID”, api_req);
}
In ‘body’ of second request, using
{
“MyID”: [{{MyID}}]
}
In the console, I have verified that I am pulling the data I want

can you post the actual response from the first call with all the included formatting?

you should have something that looks closer to this, with [ {blah}, {blah2} ] - so it is an array of results.

{
“values”: [
{
“id”: “fa25bcd2-2201-4633-8369-f3d290e090cb”,
“name”: “Test 1”
},
{
“id”: “5ec025ab-cc48-4797-95a7-066b05eed6c6”,
“name”: “Test 2”
},
{
“id”: “403212ff-0acc-4990-92ee-9a536ef66693”,
“name”: “Test 3”
},
{
“id”: “0e534567-91a2-4398-a326-5023d8ac74f6”,
“name”: “Test 4”
}
]
}

Try changing the above to this, and then reference the different env variables - your above code overwrites the same variable each time.

for (var x=0; x<api_req.length; x++) {
myID = “myID” + x
pm.environment.set(myID, api_req);
}

In the Pre-request script:

let api_req = JSON.parse(pm.environment.get(“request_env”));
let url=‘https:///api/config/v1//’;

pm.environment.set(“MyURL”, url);

for (var x=1; x<api_req.length; x++) {
pm.environment.set(“MyID”, api_req);
}

In the Body:

{
“MyURL”: [{{MyURL}}]
“MyID”: [{{MyID}}]
}

This image is from the console - no difference with your suggestion or this attempt.