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

**URL:** <https://community.postman.com/t/15-days-of-postman-for-testers-day-09-api-workflows/47916>\
**Category:** Help Hub\
**Created:** [May 29, 2023, 11:59am UTC](https://community.postman.com/t/15-days-of-postman-for-testers-day-09-api-workflows/47916 "2023-05-29T11:59:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack-robson](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jack-robson](https://community.postman.com/u/jack-robson)\
**Post date:** [May 29, 2023, 11:59am UTC](https://community.postman.com/t/15-days-of-postman-for-testers-day-09-api-workflows/47916/1 "2023-05-29T11:59:41Z")

</div>

Hi all,

I have spent a few evenings stuck on the '[Day 09’ challenge, specifically step 3.send.1 (4)](https://www.postman.com/postman/workspace/15-days-of-postman-for-testers/documentation/1559645-98685b1f-3c7d-40cc-a65c-b5a5e0b36b24?entity=&branch=&version=). 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.

```auto
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 🙏

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 30, 2023, 10:30am UTC](https://community.postman.com/t/15-days-of-postman-for-testers-day-09-api-workflows/47916/2 "2023-05-30T10:30:26Z")

</div>

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

This is the core logic for this challenge.

```auto
// 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).

---

<div class="post-metadata">

**Author:** ![jack-robson](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jack-robson](https://community.postman.com/u/jack-robson)\
**Post date:** [May 31, 2023, 2:15pm UTC](https://community.postman.com/t/15-days-of-postman-for-testers-day-09-api-workflows/47916/3 "2023-05-31T14:15:39Z")

</div>

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 !
