Member-only story
Reading CSV file in Postman
1 min readJun 23, 2020
CSV:
a,b,c
1,2,3
1,5,6
2,4,6
CSV parse output:
Approach 1: store CSV content as an environmental variable
Just copy the CSV file content and create an environmental variable and paste the content inside it
Then in test or pre-requisite step:
console.log(pm.environment.get("data"))
const parse = require('csv-parse/lib/sync')//Environmental variable where we copy-pasted the csv content
const input =pm.environment.get("data");const records = parse(input, { columns: true, skip_empty_lines: true})
console.log(records)
Approach 2: Passing the CSV content to an environmental variable through Newman (Powershell):
Then in test or pre-requisite step use the same code as above:
> $a= Get-Content -raw .\1.csv> newman run .\test.postman_collection.json -e .\test.postman_environment.json -k -r "cli,htmlextra" --env-var data=$a