cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retrieving more than 2 pages of 1000 clients from GET /networks/{networkId}/clients?

SOLVED
Highlighted
Here to help

Retrieving more than 2 pages of 1000 clients from GET /networks/{networkId}/clients?

I posted on here about a week ago on how to get more than 1 page. The solution was looking at the headers.link and there are 2 links in there with relevant 'startafter' data to give me the pages. This gave me around 1800 clients, and I thought it would be sufficient. 

 

Now, I'm needing to go back further in time and there are more than 2000 clients in this wider time span. The problem is, after making this http GET, I'm still only seeing 2 links in the headers(despite there being roughly 3500 clients in the time span). So, I'm getting a total of exactly 2000 clients from 2 links. 

 

How do I find these extra pages, so I can get all of the users?

 

Here is the headers.link that gets returned(with my network id in 5s)

 

<https://n11.meraki.com/api/v0/networks/N_555555555555/clients?perPage=1000&startingAfter=a000000&tim...>; rel=first, <https://n11.meraki.com/api/v0/networ
ks/N_555555555555/clients?perPage=1000&startingAfter=k17a74c&timespan=604800>; rel=next

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Building a reputation

Re: Retrieving more than 2 pages of 1000 clients from GET /networks/{networkId}/clients?

OK, I will break this down the way I process it and keep the specific code out of it.

 

When I call my function, I pass it the URL for the endpoint (https://n11.meraki.com/api/v0/networks/N_555555555555555/clients) and the query information (timespan=30&perPage=1000)

 

The function starts a loop and calls the endpoint with this data. The first 1000 entries are returned. It saves that data. It then looks at the header.list and checks for "rel=next". If it finds it, it then gets whatever the token value is associated and then modifies the query to include it, using your example (timespan=30&perPages=1000&startingAfter=ka1710e)

 

It then goes back to the top of the loop, checks to see if it is done, and then calls the endpoint again with the new query values. It gets the next 1000 clients and concatenates the data to the end of the previous page. Then it checks for "rel=next" again. If it finds it, it gets the new token (k17db29) and updates the query to be timespan=30&perPages=1000&startingAfter=k17db29)

 

It goes to the top of the loop and sees it is not done. Calls the endpoint again with this query. Get the next page of data and concatenates it. Let's say this is the last page. It checks for "rel=next" and does not find it. It sets the flag to tell the loop it is done and returns to the top of the loop. The loop sees it is done and exits the loop. The function then returns all of the data it collected (3 pages worth) so it can be processed.

 

Does that make it a bit clearer?

View solution in original post

5 REPLIES 5
Highlighted
Building a reputation

Re: Retrieving more than 2 pages of 1000 clients from GET /networks/{networkId}/clients?

You have to make repeated calls to the endpoint and each time, excluding the first call, specify the value for startingAfter. Each call with give you the token for the next "page" of data. That is why the Python code I posted checks for "rel=next" in the header and then updates the query string with the token it finds and keeps calling the endpoint until it no longer can find "rel=next", thus indicating that you have gotten the last page.

Highlighted
Here to help

Re: Retrieving more than 2 pages of 1000 clients from GET /networks/{networkId}/clients?

I'm so close to wrapping my head around this, so bear with me if you can.

I just want to break this down to the simplest possible components, because I don't know Python(will eventually be in Powershell), and right now just using this: https://developer.cisco.com/meraki/api/#/rest/api-endpoints/clients/get-network-clients

So, I make the initial call for 1000 clients per page and I get this header.link

<https://n11.meraki.com/api/v0/networks/N_555555555555555/clients?perPage=1000&startingAfter=a000000&...>; rel=first, <https://n11.meraki.com/api/v0/networks/N_555555555555555/clients?perPage=1000&startingAfter=ka1710e&...>; rel=next

Now, I think I get the logic here. I'm supposed to now enter startingAfter=ka1710e in my next query, so that it starts at that page and gives me another, and so on. Problem is, when I do that, here's what I get next in the header.link

<https://n11.meraki.com/api/v0/networks/N_55555555555555555/clients?perPage=1000&startingAfter=a00000...>; rel=first, <https://n11.meraki.com/api/v0/networks/N_55555555555555555/clients?perPage=1000&startingAfter=k17db2...>; rel=next

This data confuses me. Shouldn't the first link be ka1710e and the second by something much further along than what it is?









Highlighted
Building a reputation

Re: Retrieving more than 2 pages of 1000 clients from GET /networks/{networkId}/clients?

OK, I will break this down the way I process it and keep the specific code out of it.

 

When I call my function, I pass it the URL for the endpoint (https://n11.meraki.com/api/v0/networks/N_555555555555555/clients) and the query information (timespan=30&perPage=1000)

 

The function starts a loop and calls the endpoint with this data. The first 1000 entries are returned. It saves that data. It then looks at the header.list and checks for "rel=next". If it finds it, it then gets whatever the token value is associated and then modifies the query to include it, using your example (timespan=30&perPages=1000&startingAfter=ka1710e)

 

It then goes back to the top of the loop, checks to see if it is done, and then calls the endpoint again with the new query values. It gets the next 1000 clients and concatenates the data to the end of the previous page. Then it checks for "rel=next" again. If it finds it, it gets the new token (k17db29) and updates the query to be timespan=30&perPages=1000&startingAfter=k17db29)

 

It goes to the top of the loop and sees it is not done. Calls the endpoint again with this query. Get the next page of data and concatenates it. Let's say this is the last page. It checks for "rel=next" and does not find it. It sets the flag to tell the loop it is done and returns to the top of the loop. The loop sees it is done and exits the loop. The function then returns all of the data it collected (3 pages worth) so it can be processed.

 

Does that make it a bit clearer?

View solution in original post

Here to help

Re: Retrieving more than 2 pages of 1000 clients from GET /networks/{networkId}/clients?

I see I see, ahh ok I get it now. Thanks for your help
Highlighted
Building a reputation

Re: Retrieving more than 2 pages of 1000 clients from GET /networks/{networkId}/clients?

I am glad that helped. I had to look at the header.list data in a debugger as I stepped through the code and made calls to see the token changes and to see what I got after the first call, the next few calls, and then when I reached the end of the data. Being able to see that progression helped a lot in figuring out how they data was being presented and how to extract it.

Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.