saving arrays in one call and use it in another call in postman

245 views Asked by At

I am trying to use chain request feature in postman. Here is my first request: enter image description here

As you see I am trying to save configs as an array to use it in another request. Apparently post man save the array in env vars as an strings. So here I need to use the above array:

enter image description here

but not sure how as when I debug the configs sent I do not see array and instead I see:

"configuration_ids":"b21aecaa-ff79-422a-b8b3-430a32d10242,e081163f-bfeb-4462-a753-b6e0bc5b00f5,c7c0fe31-62dd-4d5d-8d57-4122cdd5394f,64896a72-40c2-4271-ab03-12b73a2e55d8,55abc706-9ed6-4f04-90dd-22c668310584"

Any help on how to achieve this is appreciated

1

There are 1 answers

0
Christian Baumann On BEST ANSWER

You don't need the join, as already pointed out in the comments.

Still, setting an environment variable calls toString(), thus you need to stringify configurationIds:

const configurationIds = Object.keys(response)

pm.environment.set("configurationIds", JSON.stringify(configurationIds));

When I set this body in the next request

{"configuration_ids":{{configurationIds}}}

it results in:

{
   "configuration_ids":[
      "b21aecaa-ff79-422a-b8b3-430a32d10242",
      "e081163f-bfeb-4462-a753-b6e0bc5b00f5"
   ]
}