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