Sophos API pagination

I am exploring Sophos API to manage our organization. I am using powershell to query for Users not assigned to use group. The results returned are max of 100(I believe so). We have over 2k users. I would like to query ALL users in the organization. I understand that I should use pagination to return all users but can’t figure out the syntax. 

I have used “Do …While  “, which seemed to work for EndPoints, but doesn’t seem to return all pages for users.

do

{
 # Query for users 

$nextKey = $response.NextKey

} while ($nextKey -ne $null)

I have nullified $nextKey at the start

could someone help with code portion to address this issue? Or a proper way to incorporate the NextKey into the user query?



Added code
[edited by: Sophos User4238 at 10:11 PM (GMT -7) on 4 Nov 2023]