Postman pre request script,Ä°mport CSV file data

Postman/Pre-request Script get csv file data and save as environment variable

When I do postmande run collection, I add the csv file, but I couldn’t manage to pull this data and save it to environment variables at the pre-request script stage.after that ı will use this varible from environment in my boddy section code to update data on the server.

console.log(price);

pm.environment.set(“istenenDeger”, price);

let lojistikmaliyeti = Number(price);

console.log(lojistikmaliyeti);

pm.environment.set(“Lojistik Maliyeti”, lojistikmaliyeti);

the code is as above. My first line is the part where I need to define the data I took from the csv file into the “price” object. I left the part where it pulls data from csv blank.

ı tryied pm.collectionvariables.get combination or fs library and split but ı didnt get right conclusion

Using CSV and JSON Data Files in the Postman Collection Runner | Postman Blog

The runner uses a special data dictionary based on the CSV headers, so to reference the values in the CSV file, it should just be data.headername.

For example…

console.log(data.price);

If you just console log the data object, it will show you all of your test data for that iteration as an object.

console.log(data);

This looks like it should be a one liner.

pm.environment.set(“Lojistik Maliyeti”, Number(data.price));

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.