1

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

Henke
  • 4,445
  • 3
  • 31
  • 44
Learner
  • 1,686
  • 4
  • 19
  • 38
  • What does the response from `/configurations` endpoint look like? – Z. Kosanovic Oct 16 '20 at 19:40
  • @Z.Kosanovic similar to this: { "b21aecaa-ff79-422a-b8b3-430a32d10242": { ..... }, "e081163f-bfeb-4462-a753-b6e0bc5b00f5": { "acl": { ........ – Learner Oct 16 '20 at 19:45
  • Okay, so the second line gets the keys and then joins them to string. Not sure if this would work, but try to delete the join part. So, it's just `... = Object.keys(response);` – Z. Kosanovic Oct 16 '20 at 19:47
  • Does this answer your question? [Postman: Can i save JSON objects to environment variable so as to chain it for another request?](https://stackoverflow.com/questions/41479494/postman-can-i-save-json-objects-to-environment-variable-so-as-to-chain-it-for-a) – Henke Feb 26 '21 at 17:20

1 Answers1

1

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"
   ]
}
Christian Baumann
  • 3,188
  • 3
  • 20
  • 37