Automatic generation of POST requests-qwery parameter chang

Good afternoon, dear members of the community.

Can you please tell me if it is possible to generate automatically POST requests with changing qwery parameter?

Conditions: there is a typical POST request with the parameter “start” which starts with 0. In the body of the response there is a value “Total” which changes daily. It is necessary to create POST requests the number of which is equal to “Total”/10. For example: 680/10=68 requests in each of which the value of the parameter "start "+10. Example: 0, 10, 20, 30, 40 and further.

Short answer is “yes”. You can have conditional logic in the pre-request script and tests tab that can loop the same request until it hits the total number of desired requests.

I’ve finished for the day, so I’ll let you think about the logic first. Try and break it down into steps.

I’ll have a proper look at this tomorrow if I get time.

You will need to set variables for the start, total, and current total.

You will need IF statements in the pre-request scripts and tests tab to control the loop, which will be done using setNextRequest().

1 Like

I had a think about this, and I suspect we can manage this loop in the tests tab.

No pre-request script needed.

As you have the “start” and “total” keys in your response.

Create a collection variable for your “Start” value and use that in the body for your request.


You can loop based on the total minus the start being more than or equal to 10.

If the total is 685, then it will stop at 680.

While that condition is true, add 10 to the currentStartNumber and then resave this to the Collection variable.

Something like…

const response = pm.response.json();

if (Math.abs(response.Total - response.Start) >= 10) {

    currentRequest =;

    let currentStartNumber = parseInt(pm.collectionVariables.get("startNumber"));
    let newStartNumber = currentStartNumber + 10;
    pm.collectionVariables.set("startNumber", newStartNumber);

} else {


For testing, I’ve set the collection variable to 600, and you can see from the console log that it run 9 times. I’ve expanded the body for the first and last request, so you can see that it started on 600 and ended on 680.

1 Like

Dear Mike, you have no idea how grateful I am. Thank you for being here! You really helped me to solve a very difficult problem for me. I wish you good luck and all the best! :handshake:


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