Hello, quick question: Can I programmatically loop over data in a JSON file, taking iteration data for the first X number of entries, and combine them into a single request?
Scenario:
Say I have 100 JSON objects to send to an API, so I use a Postman Runner to split them into 1 group of 100, or 10 groups of 10.
Some example that may not work since I wrote it in this post:
pm.iterationData.set(‘payload’, for (let i = 0; i < 100; i++)
{let currentObject = jsonArray[i];
for (let key in currentObject) {
let value = currentObject[key];
${key}: ${value};
} }
Or would it be better to format my JSON into the desired payload, then use the pre-request script to iterate over payloads in parent array? This would then be an array of objects, with each object containing an array of the exact key-values I want to send in the request.
Each “payload” to iterate over would look like this, in a big array where:
[
{
payload: {
“products”: [{
“productId”: “1234”,
“quantity”: 1
},
{
“productId”: “123”,
“quantity”: 12
},
{
“productId”: “1000”,
“quantity”: 5
}],
“location”: “WIN”
},
“payload”: {
…
}
]
pm.iterationData.set(‘payload’, payload)
curl –request blah blah
–data ‘{{payload}}’
I would have to code further to split the one large file into the array of objects with arrays.
TMI background data: My company has to modify Salesforce data for 20,000 entities. The API I created to do this accepts batchable requests. I wanted to put it in Postman so that I could share it with my team in case of unavailability for me, the person in charge.
TIA