Split Huge Json array into multiple smaller POST

I have a Json array that has 25,000 objects and I want to send to an endpoint, unfortunately the endpoint only supports a max for 1000 objects in an array before it fails out.

Is it possible to use a pre-request script to split the array into 25 small POST calls? I know that i could use Runner to POST one object per call, but since the endpoint can accept multiple objects I would like to send a larger bulk of objects to cut down on how long it takes to process in postman.

Any advice would be appreciated!

Hi @bug_nuts,

Yes, you should be able to do this using pre-request scripts. You’ll just need to use Javascript to grab chunks of the larger object, and format them appropriately. I’d recommend something like the following flow:

  1. Store your full array of object in an environment
  2. Include a dynamic variable in your request body, such as {{request_body}}, which you will set a value for in your pre-request script (this is where you array data will go)
  3. In a pre-request script, grab just indexes of the full array you need. Structure this data appropriately for your request, then use pm.variables.set("request_body",value) to set the value of your dynamic variable {{request_body}}.
  1. Keep track of which indexes you’ve already iterated through by storing this information using pm.environment.set(key,value).
  2. Loop your request using postman.setNextRequest(), until all indexes in your array have been sent.

Hope that helps! Let me know if you need a more concrete example.

Thank you so much! I got close , but didnt understand I could just put the full array into an environment variable.

I’ll give it a shot and let you know if I run into any issues.

Cool! Just know the array in the environment will be stored as a string, so use JSON.parse() to reconstitute it. :slight_smile: