My question: Value of the field “load_guids” must be an array. I’m using {{reportsLoadGuids}} as a value of the field “load_guids” but I get a JSON parse error
I’ve already tried: tried to cover the variable in brackets (like this [{{reportsLoadGuids}}] ) and discover it (like this {{reportsLoadGuids}} ), the error stays the same
Hi, as I’ve written in I’ve already tried section, I’ve tried without brackets in the body, but still get an error, then I noticed on your screenshot how the variable looks like, mine looks different and when I change the variable array by your example everything works fine.
The problem is that I’m setting an array and adding items to it through another request which creates a single item with this script:
const first_load_id = jsonData.data.guid;
var load_guids = pm.collectionVariables.get("reportsLoadGuids");
var load_guidsA = [load_guids];
if (load_guidsA == ""){
pm.collectionVariables.set("reportsLoadGuids", first_load_id)
}else if (Array.isArray(load_guids) == false){
load_guidsA.push(first_load_id) &&
pm.collectionVariables.set("reportsLoadGuids", load_guidsA);
}else if (Array.isArray(load_guids) == true){
load_guids.push(first_load_id) &&
pm.collectionVariables.set("reportsLoadGuids", load_guids);
}
Postman stores variables as strings. If you store objects or arrays, remember to JSON.stringify() them before storing, and JSON.parse() them when you retrieve them.