# GitHub api & setNextRequest

**URL:** <https://community.postman.com/t/github-api-setnextrequest/26373>\
**Category:** Help Hub\
**Created:** [August 2, 2021, 10:02pm UTC](https://community.postman.com/t/github-api-setnextrequest/26373 "2021-08-02T22:02:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigz212](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/craigz212/32/7312_2.png) [@craigz212](https://community.postman.com/u/craigz212)\
**Post date:** [August 2, 2021, 10:02pm UTC](https://community.postman.com/t/github-api-setnextrequest/26373/1 "2021-08-02T22:02:16Z")

</div>

I am so close to a solution, i can almost taste it! i’m working with the GitHub api (enterprise edition, not public GitHub) and am querying an endpoint (users) that has many pages of results.

My initial request is to `{{host}}{{base}}users` and when run, it goes and gets the first 30 results. (the host and base variables are configured and working.)

In my tests i’m checking for a “Link” header, which i do receive and it looks like this:  
`<https://hostname/api/v3/users?since=33>; rel="next", <https://hostname/api/v3/users{?since}>; rel="first"`  
In the tests i split on the “,” resulting in a ‘next’ link which i then use to create an environmental variable (named “next”) which after the 1st run looks like:  
`{{host}}{{base}}/users?since=33`  
(except the variables are expanded at this point and it looks like a url, ex:  
`https://my.github.instance/api/v3/users?since=33`)

i then use:  
`postman.setNextRequest(pm.environment.get("next"))` and end with  
`else postman.setNextRequest(null)` this, i believe should set up a loop until we stop getting “next” links, as in we are done.

however after the first page of results is returned it never runs the `NextRequest`.

if i open the request in runner then things go a bit sideways.  
as there is the single request that i want to run in a folder with about 3 prior efforts (all failed) i deselect all but the one request.

it then asks for number of runs, which of course i can’t really know how many i need, but for testing i’ve ran it 2x.

there is a complaint about the request not having tests, although it does.

i suppose there is somewhere in runner (which i am quite unfamiliar with) to configure it to use the tests contained in the request.

anyhow, it does go and run two times, and from the console i can see that my configured tests do run, as the tests output custom strings to console.log.

anyhow, it completes the first time, and it goes ahead and creates the environmental variable `next`, but then doesn’t use that link as the `NextRequest`, it simply repeats the initial request. (i’ve tested with more than 2 runs as well, with up to 10 and it simply repeats the initial request 10 times.)

If i manually enter the value of the `NextRequest` variable it will go ahead and get the next 30 results, update the environmental variable `next` by the correct increment, and appears ready for another run, which would start there.

so i want this to work, i suppose out of runners, and it of course should respect and follow the `NextRequest` link, however i’m not at all certain what needs to happen.

also, i don’t remember the ‘no tests’ error from earlier testing, i’ve just picked this up again and caught that surprise (i think) for the first time today.

i can paste my script in or anything else that may prove helpful, just let me know.

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [August 5, 2021, 2:14pm UTC](https://community.postman.com/t/github-api-setnextrequest/26373/2 "2021-08-05T14:14:32Z")

</div>

> [@craigz212](#):
>
> postman.setNextRequest

I just wanted to point out that postman.setNextRequest takes as an argument the **name** of a request, not an URL.

---

<div class="post-metadata">

**Author:** ![craigz212](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/craigz212/32/7312_2.png) [@craigz212](https://community.postman.com/u/craigz212)\
**Post date:** [August 5, 2021, 7:48pm UTC](https://community.postman.com/t/github-api-setnextrequest/26373/3 "2021-08-05T19:48:24Z")

</div>

@vdespa thanks for the tip.

so i am thinking perhaps of creating a 2nd request and using it’s name as the argument to `postman.setNextRequest` which could in it’s Pre-request script check that there is a URL contained in the variable `next` and if so go ahead and load it.

however, that gets me 1 additional step, when it’s time to loop i’m again looking down the barrel of `postman.setNextRequest`.

so, how do i create a loop condition where it will keep setting, checking, and calling the `next` variable until there is not a next value returned?

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [August 6, 2021, 7:22am UTC](https://community.postman.com/t/github-api-setnextrequest/26373/4 "2021-08-06T07:22:26Z")

</div>

You do need some JavaScript magic to get this running.

While the following tutorials don’t address the exact problem you are having, I think the JavaScript bit can help you get new ideas:

[![](https://img.youtube.com/vi/FWYKOR0Zj28/maxresdefault.jpg "Advanced workflows (request chaining) with Postman") ](https://www.youtube.com/watch?v=FWYKOR0Zj28)

[![](https://img.youtube.com/vi/MOdMKrjTOi4/maxresdefault.jpg "Data-driven testing with different data sets for each request") ](https://www.youtube.com/watch?v=MOdMKrjTOi4)
