15 days of Postman for testers - Day 09 (API Workflows)

Hi all,

I have spent a few evenings stuck on the 'Day 09’ challenge, specifically step 3.send.1 (4). I can see that the request increments the pageNumber variable each time there is another page available, but the call only returns one page of results and doesn’t appear to run the postman.setNextRequest('get starships'); portion and cycle through the remaining pages until nextRequest == null.
I expect that this is an easy thing to fix but I’ve been staring at it for so long that I can’t see for the wood for the trees and needed a fresh pair of eyes.

The specific step is below:

  • Add another script to set the next request called to be the get starships request if the next page is available, so that running this folder in its entirety would page through all the starships in order until there are no more pages available.
let response = pm.response.json();
console.log(response.count)
let nextRequest = response.next;

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.variables.set(`nextRequest`, nextRequest);
let currentPage = pm.collectionVariables.get(`pageNumber`)
if(nextRequest !== null){
    currentPage++;
    pm.collectionVariables.set(`pageNumber`, currentPage);
    //console.log(pm.collectionVariables.get(`pageNumber`))
    postman.setNextRequest(`get starships`); // This bit is not working
}

//pm.collectionVariables.set(`pageNumber`, 1); // To reset the collection variable

If I used a While statement (which seems the most obvious to use here), the pageNumber variable doesn’t increment. When running the code above as it, the response takes ~30 seconds and only returns 10 results (the first page) out of the total 36.

I’ve already tried: While statements, Do-While statements, scoured every related article in the forum and across the web but to no avail.

Thank you :pray:

Break down your logic into steps, and then create code for those steps.

This is the core logic for this challenge.

// parse response
// console log response count

// test for status code 200

// set current speed - local variable (parse collection variable)
// console log current speed.

// for each loop (for each ship)
	// if ship max_atmosphering_speed is more than current speed
		// set new ship name and current speed
		// console log both elements
// end of loop

// set current page number (local  variable) from collection variable

// if response.next is not null
	// increment current page number	
	// console log current page number
	// update the collection variable for page number
	// setNextRequest goes here

You are running this in the collection runner? (As setNextRequest only works with the runner).

1 Like

The Runner!!

I didn’t know that setNextRequest only works in the CollectionRunner, I just kept hitting send in the request and going mad.

Thank you so much @michaelderekjones !