Request working when manually run, but not with collection runner

Hi All,

Sorry if this isnā€™t the place to ask this. My collection is running succesfully when run manually, but failing when run via collection runner.

The 1st request is a GET that pulls data from an API, passes the data into an array, and stores it in an environment variable as a JSON array.

  • Array being created: var name = [];
  • Data from request being stored into JSON array: name.push(data[i].respondentDetails.name);
  • Array being stored as variable Name: pm.environment.set(ā€˜Nameā€™, JSON.stringify(name));

The 2nd request is a POST that parses the environment variable storing the JSON array, and sets a new environment variable as the first item in the JSON array.

  • Name variable being passed: var name = JSON.parse(pm.environment.get(ā€˜Nameā€™));
  • 1st item of JSON array being stored as variable current_name: pm.environment.set(ā€˜current_nameā€™, JSON.stringify(name[0]));

This works fine when each request is run manually; and when a collection runner is manually triggered; however fails when a collection runner is run from a schedule.

The 1st request runs fine, but the 2nd fails, throwing up the following error message: JSONError: No data, empty input at 1:1

I am really struggling to troubleshoot this issue, and any help would be much appreciated!

Thanks in advance.

It sounds like its failing because of the environment variables.

Console log the environment variables before you try an use them.

It might give you a better idea of what is happening. Whether the variables are available at all or returning undefined.

You canā€™t parse an undefined or null variable hence the error.

From what you have told us, it sounds like it does work with the collection runner, but fails when its run from a schedule.

Are you including the environment in the ā€œrun configurationā€.

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