Hi there! I’m having issues where I need to send multiple identical API calls to my endpoint with different attribute values. I am attempting to do this using multiple runner iterations with a pre-request script. I’ve scrubbed this but this is the behavior I’m getting. My first 4 variables are synchronized though not starting at variable value 0, my 5th variable is totally out of synch with the rest. I am no JS expert by any means, in fact I havent touched JS in about 8 years so I’m struggling quite a bit. I know the .shift() method is going to shift my arrays so I’ve added a prepending null value to each of my arrays however, my 5th variable is still off by X. Any help would be appreciated!!
{
“Hotelname”: “{{hotelname}}”,
“HotelOwner”: “{{hotelOwner}}”,
“Address”: “{{address}}”,
“State”: “{{state}}”,
“zip-code”: “{{zip}}”
}
let hotelnames = pm.collectionVariables.get(“hotelnames”);
let hotelOwners = pm.collectionVariables.get(“hotelOwners”);
let addresses = pm.collectionVariables.get(“addresses”);
let states = pm.collectionVariables.get(“states”);
let zips = pm.collectionVariables.get(“zips”);
if(!hotelnames || hotelnames.length == 0){hotelnames = [“Hotel-1”, “Hotel-2” “Hotel-3”, “Hotel-4”, “Hotel-5”];
}
if(!hotelOwners || 'v.length == 0){hotelOwners = [“HotelBrand-1”, “HotelBrand-2” “HotelBrand-3”, “HotelBrand-4”, “HotelBrand-5”];
}
if(!addresses || addresses.length == 0){addresses = [“HotelAddress-1”, “HotelAddress-2” “HotelAddress-3”, “HotelAddress-4”, “HotelAddress-5”];
}
if(!states || states.length == 0){states = [“HotelState-1”, “HotelState-2” “HotelState-3”, “HotelState-4”, “HotelState-5”];
}
if(!zips || zips.length == 0){zips = [“HotelZip-1”, “HotelZip-2” “HotelZip-3”, “HotelZip-4”, “HotelZip-5”];
}
let currentHotel = hotelnames.shift();
pm.collectionVariables.set(“Hotelname”, currentHotel);
pm.collectionVariables.set(“hotelnames”, hotelnames);
let currentOwner = hotelOwners.shift();
pm.collectionVariables.set(“HotelOwner”, currentOwner);
pm.collectionVariables.set(“hotelOwners”, hotelOwners);
let currentAddress = addresses.shift();
pm.collectionVariables.set(“Address”, currentAddress);
pm.collectionVariables.set(“addresses”, addresses);
let currentState = states.shift();
pm.collectionVariables.set(“State”, currentState);
pm.collectionVariables.set(“states”, states);
let currentZip = zips.shift();
pm.collectionVariables.set(“zip-code”, currentZip);
pm.collectionVariables.set(“zips”, zips);
status 200, output:
Hotel-2
HotelBrand-2
HotelAddress-2
HotelState-2
HotelZip-4
Hotel-3
HotelBrand-3
HotelAddress-3
HotelState-3
HotelZip-5
Hotel-4
HotelBrand-4
HotelAddress-4
HotelState-4
HotelZip-1
Hotel-5
HotelBrand-5
HotelAddress-5
HotelState-5
HotelZip-2
Hotel-1
HotelBrand-1
HotelAddress-1
HotelState-1
HotelZip-3
is it possible to force all of my values to an initial value using:
let hotelnames = pm.collectionVariables.get(“hotelnames”);
hotelnames++
let hotelOwners = pm.collectionVariables.get(“hotelOwners”);
hotelOwners++
let addresses = pm.collectionVariables.get(“addresses”);
adresses++
let states = pm.collectionVariables.get(“states”);
states++
let zips = pm.collectionVariables.get(“zips”);
zips++
pm.collectionVariables.set(“Hotelname”,“Hotel-1”)
pm.collectionVariables.set(“HotelOwner”,“HotelOwner-1”)
pm.collectionVariables.set(“Address”,“HotelAddress-1”)
pm.collectionVariables.set(“State”,“HotelState-1”)