Skip to main content

Hi Automox Support,



Good Day.



We are adjusting our automation to ingest the /servers into an auxiliary table. The automation does not know the size of the of the entire record set from /servers. For example, we are trying to return 7500 servers to iterate through. So we have to set an arbitrary number of iterations of number devices divisible by 500.



Are there any examples on how Automox would recommend iterating through API calls, with more than 500 records returned?



Thanks in advance.



Chuck


@habrnero

Hey Chuck, check out this thread: API Issue


Short answer is loop until the number returned is less than 500 (which could be 0 or anywhere in between), but that tells you you’re at the end.


Alternatively, each server object will have a property of “total_count” that tells you how many results are in your set. So you can take that and iterate an appropriate number of times. Divide total_count by 500, round down and add 1.


Not sure what exactly you are attempting to accomplish with your script, but what I’ve found is I will iterate through all of my devices and find my deviceID, and push that to a text file somewhere on the system. Then a little fuzzy logic to check for that file during subsequent deployments, and if it exists, we don’t have to do a full API iteration parse. I would love if automox found a way to hardcode a device’s API ID so we could just call it instead of all these costly API calls.


$lengthPerPage=100

$pageCounter=0

do

{

$apiUrl = "https://console.automox.com/api/servers?l=$lengthPerPage&p=$pageCounter"

$response = Invoke-RestMethod $apiUrl -Method 'GET' -Headers $headers -Body $body

$a = $response | ConvertTo-Json

$maxItems = $response.results.count

$pageCounter++

} while ($maxItems -ne 0)

Reply