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.
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:
Store your full array of object in an environment
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)
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}}.
Keep track of which indexes youโve already iterated through by storing this information using pm.environment.set(key,value).
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.
Hi @john-paul,
I am a newbie and learning Postman. I have a similar query that @bug_nuts has logged a while ago.
I have a large JSON array string that I have stored in an environment variable. This JSON array has over 1000 objects. However, I want to split the array and each small array will have 50 objects. Then, I want to pass each small array to โrequest_bodyโ in a loop until the full POST call is completed.
I would appreciate it if you could give me an example.
Kind regards