# Reading Multiple Response Bodies With Non Key/Value Pair

**URL:** <https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347>\
**Category:** Help Hub\
**Created:** [October 14, 2019, 11:43am UTC](https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347 "2019-10-14T11:43:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrobar](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jrobar](https://community.postman.com/u/jrobar)\
**Post date:** [October 14, 2019, 11:43am UTC](https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347/1 "2019-10-14T11:43:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jonsworkalias](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jonsworkalias/32/3153_2.png) [@jonsworkalias](https://community.postman.com/u/jonsworkalias)\
**Post date:** [October 15, 2019, 4:38pm UTC](https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347/2 "2019-10-15T16:38:23Z")

</div>

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

Is the response valid JSON? [Check here - valid JSON?](https://jsonformatter.curiousconcept.com/)

---

<div class="post-metadata">

**Author:** ![jrobar](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jrobar](https://community.postman.com/u/jrobar)\
**Post date:** [October 15, 2019, 5:03pm UTC](https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347/3 "2019-10-15T17:03:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jonsworkalias](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jonsworkalias/32/3153_2.png) [@jonsworkalias](https://community.postman.com/u/jonsworkalias)\
**Post date:** [October 15, 2019, 5:16pm UTC](https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347/4 "2019-10-15T17:16:20Z")

</div>

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

you should have something that looks [closer to this](https://reqres.in/api/users/), with [{blah}, {blah2}] - so it is an array of results.

---

<div class="post-metadata">

**Author:** ![jrobar](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jrobar](https://community.postman.com/u/jrobar)\
**Post date:** [October 15, 2019, 6:08pm UTC](https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347/5 "2019-10-15T18:08:38Z")

</div>

{  
“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”  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![jonsworkalias](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jonsworkalias/32/3153_2.png) [@jonsworkalias](https://community.postman.com/u/jonsworkalias)\
**Post date:** [October 15, 2019, 6:22pm UTC](https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347/6 "2019-10-15T18:22:08Z")

</div>

> [@jrobar](#):
>
> for (var x=0; x\<api\_req.length; x++) {  
> pm.environment.set(“MyID”, api\_req);  
> }

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);  
}

---

<div class="post-metadata">

**Author:** ![jrobar](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jrobar](https://community.postman.com/u/jrobar)\
**Post date:** [October 17, 2019, 2:23pm UTC](https://community.postman.com/t/reading-multiple-response-bodies-with-non-key-value-pair/8347/7 "2019-10-17T14:23:04Z")

</div>

_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.

 ![question-api-loop-01](https://us1.discourse-cdn.com/getpostman/original/3X/b/e/be1bd9d2159fd9ac7c81f1dbd9f73973b3eea4d5.png)
