Remove quotes from a response to use it as variables

Hi together,
I’m new here an I got a respons which I want to pass into another Call. Now I struggle because I need to remove the “” from the id, otherwise I can’t pass the variable into my other Call.
This is my response so far:

let response = pm.response.json();

ids = _.map(response.value, ({ id }) => ( id ));

pm.globals.set(‘WID’, JSON.stringify(ids));

Can anybody help with this problem?

Best,
Kathrin

Hi @maintenance-geoscie8

You could use slice

So if the value was “3426432”… using slice(1,1) would remove first and last character so the result would be just the numbers without the quotes.

Or try the approach here;

1 Like

HI @w4dd325 ,
where would I put the slice into my code? Into the code where my variable should be or in the code where I get my variable? Sry for asking, I’m completly new to this topic :slight_smile:

Best,
Kathrin

Ok I can remove the “” If I use the enviroment variable…but now I would like to put the result which is in my case 2 values comma seperated into my POST call - I can’t put them both into the Call I have to put them seperatly into it. Can someone help?


Best,
Kathrin

Are you using the comma-separated values as 1 value, or would they have to be split out into 2 separate values?

1 Like

Hi @w4dd325 ,
the values should be splitted into single IDs. I created a collection to use interations but I’m still struggeling with the single values instead of comma separated values.

Best,
Kathrin

You would probably be better to save the values as an array then.

//Parse response
const response = pm.response.json();

//Setup array
myArray = [];

//Loop all items you need to save
for (i = 0; i < response.length; i++)
{
    //Use "Push" to add each item to your array
    myArray.push(response[i].name);
}

//Display the whole array
console.log(myArray);

//Pick a specific item from the array
console.log(myArray[4]);
console.log(myArray[42]);
console.log(myArray[57]);

Example output;

1 Like