I am trying to find a better solution to run the Do loop, Until all contacts are Collected. Currently I have over estimated the amount of pages to just go until 20 pages. Is there a better method.
I tried $responseheader.HAS_MORE_RECORDS -notcontains "TRUE" but that was not returning the results.
$results = [System.Collections.ArrayList]@()
do {
#Starting URL, 50 contacts per page
$url = "api/v1/contacts/&page=$Page"
$response = Invoke-RestMethod $url -Method Get -Headers $Header -ResponseHeadersVariable responseheader
# Adds each Response to Results array
$response.foreach({$results.add($_)}) | out-null
#increases Page number
$page++
#Ends Do loop at page 20
} until ($Page -eq 20)