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โ]
-
0: โ5cb4477d5db0434dbfd3466235152720โ
-
1: โ70c9ff9e1b2a4af6be42d7adc344b713โ
-
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โฆ