Looping over array to change input of request - Where should the array be stored?

Context: New user (about 5 days) attempting to pass about 100 sets of lat/long coordinates via several requests (about 12) within a collection to an API on a monthly basis and manually inserting each lat/long coordinate in 12 GET requests is not feasible.

8 of the requests within the collection require a different set of lat/long coordinates - coordinates at another geographic level, i.e. Census Tract.

I already have the 100 latitude and longitude coordinates but currently just using two sets of latitude/longitude coordinates to develop the pre-request script, test scripts, variables, etc. and successfully run prior to using all 100 coordinates.

(I believe that it is possible to “auto-generate” the latitude and longitude coordinates for a particular geographical region and then feed this into the requests. This will be tackled later.)

Have reviewed the prior post titled “How to loop over array to change input of request?” and it mirrors about 80% of what I want to accomplish.

Steps taken so far include;

Modified the URL similar to the following format:
https://…/bylocation?latitude={{latitudeArray}}&longitude={{longitudeArray}}

Created a CSV files with two lat/long coordinates

Utilized the Collection Runner

Imported the CSV file into Postman

Tried the above-mentioned steps numerous times and still receive the error

"JSONError: No data, empty input at 1:1 "

Any insight as to how this error can be resolved?

Thanks in advance.

Attached are the pertinent files:


Try breaking down your problem into smaller, more manageable steps.

"JSONError: No data, empty input at 1:1 "

indicates that whatever you have stored in those environment variables is not valid JSON. Most likely they are empty.

Create a more simple collection, work with postman-echo.com as a dummy API, use console.log to understand and debug your scripts.

Thanks for the insight.

Just attempting to run one request within one collection as I concur - a modular approach is best.

Immediate goal is to successfully extract data for just one request using the environment variables within the Pre-request script;

latLongIndex
latitudeArray
longitudeArray

Then, will try the Data File approach.

Additional steps taken include;
Switched from a POST request to a GET request
Input the initial values for the variables “latitudeArray” and “longitudeArray”

Consistently receive the following error

“There was an error in evaluating the Pre-request Script:ReferenceError: Cannot access ‘latitudeArray’ before initialization”

With a limited, but expanding, frame of reference as it relates to Postman - it appears that the Environment variables are not processing.

Pertinent files displayed below.

Thanks in advance for any additional insight.



Try breaking down the script into even smaller pieces that you can understand. It is still too big.

I would remove everything and start from scratch.

1 Like