Hello everyone,
for some reason I cannot get my pre-request script to work. It is suppposed to read some variables from a csv file and do some data wrangling to change my request every time.
Here’s the code:
var names = pm.variables.get("Artikel").split(",");
console.log(names);
var sku = sku.iterationData.get("Artikelnummer").split(",");
var prices = pm.iterationData.get("Preis").split(",");
var line_items = [];
for (let i = 0; i < names.length; i++) {
var line_item = { variant_id: null, price: prices[i], name: names[i], sku: sku[i],title: names[i],quantity: 1};
line_items.push(line_item);
}
//var line_items_json = JSON.stringify(line_items);
//pm.environment.set("lineItems", line_items_json );
pm.environment.set("lineItems", line_items )
console.log(pm.environment.get("lineItems"));
I get the following error: TypeError: Cannot read properties of undefined (reading ‘iterationData’). Strangely enough though, the console.log works and prints the data to the console. Afterwards the script stops executing though. Am I doing something wrong?
Thanks very much for your help!