Iterating through pages API
Hi, I'm using the API to pull a list of devices from various groups. When I run the following the command I'm getting a partial list of my devices:
Invoke-RestMethod -Uri "https://webapi.teamviewer.com/api/v1/managed/groups/{id}/devices" -Method Get -Headers @{authorization = "Bearer $apikey"}
The result is returning a nextPaginationToken, but I'm not sure how to use that in order to get the next part of the list of devices.
Any help on this is appreciated.
Thanks
Answers
-
Did you ever get help with this? I'm in same boat. I wrote a PowerShell to pull down vulnerabilities for all devices. When I query the API to first produce a device list, it tops out at 1,000 devices. Clearly I need to use pages, but I could use some documentation on this.
0 -
Hey, this is more or less what you do to iterate through pages. When you run the Invoke-RestMethod command the first time, one of the items returned is named nextPaginationToken, you plug that into the same command as
"?paginationtoken=yournextpaginationtokenhere"
$token = 'yourtokenhere' #Declaring the Token variable
#Command to get the information from the MCO
$headers = New-Object "System.collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $token")
Invoke-RestMethod 'https://webapi.teamviewer.com/api/v1/managed/devices' -Method 'GET' -Headers $headers#Show paginated entries
Invoke-RestMethod 'https://webapi.teamviewer.com/api/v1/managed/devices?paginationtoken=yournextpaginationtokenhere' -Method 'GET' -Headers $headersgood luck
0