iterationData for csv files. using Newman as programmatically not CLI

Not able to use iteration data while calling a PUT API

  • My API {{myurl}}/api/layouts/{{id}} - {{myurl}} is environment, and {{id}} i am reading from CSV file

  • Using Newman as programmatically
    var newman = require('newman'); var fs = require('fs'); newman.run({ collection: require('./putlayout.postman_collection.json'), environment: require('./local.postman_environment.json'), iterationCount :2, iterationData: require('./id.csv'), insecure: true, reporters: 'cli', }).on('console', function (err, logs) { console.log(logs.messages); });

  • Error i am facing : /Users/chetatri/Desktop/gtmhub/newman/id.csv:1
    70b2ae4e-f421-4af8-8593-b40355ad08c2
    ^^
    SyntaxError: Invalid or unexpected token
    70b2ae4e-f421-4af8-8593-b40355ad08c2

  • csv file used
    (base) ESZAR1M0186:newman chetatri$ cat id.csv
    id
    9ef99ac4-b2dc-4943-a562-e292f7bd12c7
    a8e0dadd-7257-4e6b-937d-b22b8509a508
    (base) ESZAR1M0186: Newman chetatri$

  • Example for JSON is available
    : iterationData: [{ โ€œvarโ€: โ€œdataโ€, โ€œvar_betaโ€: โ€œother_valโ€ }],

Try the following and see if that helps:

newman.run({ 
    collection: require('./putlayout.postman_collection.json'),
    environment: require('./local.postman_environment.json'), 
    iterationData: './id.csv', 
    insecure: true, reporters: 'cli', 
}).on('console', function (err, logs) { console.log(logs.messages); });

Iโ€™ve removed require() function for iterationData fieldโ€™s value, and that seems to have done the trick!

I actually checked by removing require() function for Collection and Environment as well, and that works as well.

3 Likes

Thatโ€™s solution helped me for that problem! Many thanks!

This works for me as well! What would cause that!? Require is only for importing json?

Thanks a lot! That helped me!

1 Like