VeritasOS / netbackup-api-code-samples

Contains code samples that demonstrate the use of NetBackup REST API
MIT License
53 stars 52 forks source link

pagenation #64

Closed ntbritton closed 4 years ago

ntbritton commented 4 years ago

Can we get a powershell and ansible example of how to return all pages to a var?

ntbritton commented 4 years ago

Here is how i did it in powershell. I was not sure how else is the best way to get this added to the examples for everyone to see.

Get all Assets

$allPages = New-Object System.Collections.ArrayList @() $page = 0

do { $page = $page + 100 write-host "Current page processing is $page" $uri = $basepath + "/assets?page%5Boffset%5D=$page&page%5Blimit%5D=$itemlimit&sort=-lastDiscoveredTime"

$response = Invoke-WebRequest -Uri $uri -Method GET -ContentType $content_type -Headers $headers $content = (ConvertFrom-Json -InputObject $response) foreach ($contentpage in $content.data.attributes) { $allPages.Add($contentpage)|Out-Null } $allPages.Count } while ($content.links.self.href -ne $content.links.last.href) $allPages.Count

kenogden commented 4 years ago

There is also: $content.meta

pagination                                                                                                                                                                                                                                                            
----------                                                                                                                                                                                                                                                            
@{next=10; pages=4; last=30; offset=0; limit=10; count=34; page=0; first=0}    
ntbritton commented 4 years ago

That would work to loop through all the pages as well. I had not seen that one.