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ā)