How to send variable with multiple double quotes

Hi ,

I have 2 api calls Get and Post.

I am saving the value of Get using

var jsonData = JSON.parse(responseBody);
pm.collectionVariables.set(“ids”, jsonData.resources);

Value of ids is something like

ids=“abc”,“efg”,“asda12”

In post i am sending the value of “ids” in body like below

{
“ids”: “{{ids}}”
}

however, the postman is removing the quotes and sending it as “abc,efg,asda12” and this is giving 404 not found error .

can someone please help me on how to send the data with quotes ?

thank you!

Is that valid JSON?

It’s not an array (no square brackets) and is also not a single string.

Usually, you are talking about escape characters, but not sure how this would work. Postman will wrap quotes around it as it thinks it should be a single string element which is what it’s done.

Can you try the following and post the Console log?

console.log(pm.response.json().resources)
1 Like

hi jones,

thank you for your response. please find the console log below

(3) [“5cb4477d5db0434dbfd3466235152720”, “70c9ff9e1b2a4af6be42d7adc344b713”, “9296ea4f799d436db380c267f8ad94ff”]

  1. 0: “5cb4477d5db0434dbfd3466235152720”

  2. 1: “70c9ff9e1b2a4af6be42d7adc344b713”

  3. 2: “9296ea4f799d436db380c267f8ad94ff”

Ok, so that is a flat array with three elements in. (You can see the square brackets).

To store and use these as variables you have to JSON.stringify() them before storing, and JSON.parse() them when you retrieve them.

array = ["5cb4477d5db0434dbfd3466235152720", "70c9ff9e1b2a4af6be42d7adc344b713", "9296ea4f799d436db380c267f8ad94ff"]

pm.collectionVariables.set("ids", JSON.stringify(array));

Otherwise it will store it like this…

image