GitHub api & setNextRequest

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.

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

@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?

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: