Send multiple get request and then a single post request

I had a bit of time today, so I created a simple example.

This is using a POST request to Postman Echo to loop through the responses.
The final request is a GET request to Postman Echo.

I’ve not done the 5% logic, but I’ve just incremented ltp by 1 each time until I hit 10.
You’ll have to code that bit yourself.

Using a very simple body with the ltp value coming from a collection variable. (Initially set to 5).

{
"ltp": {{ltp}},
"Price": 5.6,
"High": 5.6
}

This is the Tests tab.

response = pm.response.json()
var currentltp = response.data.ltp;
console.log(currentltp);

pm.test(`ltp=${currentltp} - Status code is 200`, () => {
    pm.response.to.have.status(200);
});

if (currentltp < 10){

    currentltp++; // increment by 1
    pm.collectionVariables.set("ltp",currentltp);    
    postman.setNextRequest("Request_Name"); // keep looping until ltp is more than 10

} else {
    
    pm.sendRequest({
        url: 'https://postman-echo.com/get?ltp=' + currentltp,
        method: 'GET',
     }, function (err, res) {
        if (err) {
            console.log(err);
        } else {
            pm.test("Final GET Request - Status code is 200", () => {
                pm.expect(res).to.have.status(200);
            });
            
            let resJson = res.json();

            pm.test("Final GET Request - ltp=10", () => {
                // console.log(resJson);    
                pm.expect(parseInt(resJson.args.ltp)).to.eql(10);
            });

            
        }
    });

    currentltp++; 
    pm.collectionVariables.set("ltp",currentltp);  // 11
    // the pre-request script will set ltp back to 5 once it hits 11

    postman.setNextRequest(null); // break the loop

}



I’ve also added a tiny bit of code to the Pre-request script to set ltp back to 5 once the threshold has been hit. (So I don’t have to go and reset the variable each time I run the test).

var currentltp = pm.collectionVariables.get("ltp");

if(currentltp === 11){
    pm.collectionVariables.set("ltp",5); // set LTP back to 5.
}