How to gather value from Json Body and make it a variable for chaining?

Get command = {{url}}/networkAsset/xxxxx/sites
Initial GET returns JSON data containing all sites, I’m trying to discern how to capture the “id” data to use. Essentially I’d like to:
a. Acquire the id-set as variable
b. Use it in 3 other gets
c. And then use the next id until there aren’t any more in the list

[
{
“self”: {
“href”: “website”
},
“account”: {
“href”: “/fooDomain/fooServlet/paths/12”
},
“id”: “xxxxxxxx-20b6-xxxxx-89ad-xxxxxxxxxx”,
“type”: “Site”,
“value”: “name of Site”,
“assetInfo”: {
“metadata”: {
“tags”: ,
}
}
},
]

For each id I need to make 3 other calls

  • {{url}}/networkAsset/xxxxxx/shoes?siteId
  • {{url}}/networkAsset/xxxxxx/apples?siteId
  • {{url}}/networkAsset/xxxxxx/oranges?siteId

How do capture and set each id as a variable to use in subsequent per site gets/calls?

Hi @BlkKnight01, welcome to the community!

So to confirm, you need to get/generate a list of IDs, then run each of those three requests for each ID?

I just built an example Collection that does this. :slight_smile:

Go to the following docs page for a description of how it works, and click the Run in Postman button to get your own copy to play around with:

Hope that helps! Let me know if you have questions.

Greatly appreciate the reply john-paul. I ran the the initial get request for the id parse, and env variable set. The test error out:

HI @BlkKnight01, do you have an environment selected in the app? I think I forgot to include one on the docs page.

no … running without an environment but everything json.

one dataset in reply: not sure if where the id field is in the reply makes a difference.

[
{
“self”: {
“href”: “https://xxxxxxxxxxx/xxxxxxxx/xxxxxx/xxxx/953823aa-20b6-4be9-89ad-b9b37c92609b” --> need string after the last “/”
},
“account”: {
“href”: “/fooDomain/fooServlet/paths/12”
},
“id”: “953823aa-20b6-4be9-89ad-b9b37c92609b”, --> need alpha/numeric string between quotes
“type”: “xxxx”,
“value”: “xxxxxxxxxxxxxxxxxxxxxx”,
“assetInfo”: {
“metadata”: {
“tags”: ,
“props”: {
“address”: “xxxxxxxxxxxxxx”,
“areaCount”: “3”,
“name”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,
“organizationId”: “xxxxxx-xxxxxxxxxxxx-xxxxxxxxxx”
}
},
“enabled”: true
}
},

Got it. So, a couple things to note:

  1. The code I wrote requires that an environment is selected to work (but you don’t have to put anything in it — everything that is needed is added by the code)
  2. You’ll need to modify the first two line of code in your screenshot to suit the response you’re working with. In my Collection, the GET ID list request has a response that contains:
    {args:{idArray:[1,2,3,4,5,...]}}
    …so idArrayString = pm.response.json().args.idArray will work.

The basic principle here is to use Javascript to create a 1 dimensional array that contains all your ids ([1,2,3,4,5,....]), then store the stringified version of that array and its length in the environment.

Hope that helps!