Collections runs fine in Runner but not in Newman

Hi!

I have a collections that runs perfectly fine in the runner. But when trying it with Newman one particular script fails.

var users = JSON.parse(pm.environment.get(“users”));
var jsonBody = users.shift();
pm.environment.set(“users”, JSON.stringify(users));
pm.environment.set(“jsonBody”, JSON.stringify(jsonBody));

results in:

  1. JSONError No data, empty input at 1:1
    ^
    at prerequest-script
    inside

The enviroment is exported and used in newman with:
newman run test.postman_collection.json -e test.postman_environment.json

Can’t find the issue at al, please help me :slight_smile:

can you check if the value is available in the intital value of your environments ?

export postman environments will not export the values available in current value but rather only the values available in initial value.

1 Like

It was not set as initial.
Thank you!

Hey @joachim.sjogren

The script alone is quite meaningless as those variables can and could reference anything.

  • What does users look like?
  • What’s the shift doing in that context?
  • What does the jsonBody like like?
  • Have you added that variable to the pre-request?
  • What is actually sent in the request each time (I’m guessing it’s doing it more than once if you’re shifting things)
  • What version of Newman are you running?

I have loads more questions about something as basic as this so without expanding on your question and giving folks more information about the overall usecase here - It’s basically down to guess work.