
SebastienU.52034 (Customer) asked a question.
We want to create a script on powershell to add in a okta group all users have second factor enrolled
We arrived to list the first 200 users but not all.
We have a problem with '@odata.nextLink' that return null value.
Can you help us please ?
Thanks
---------------------------------
$apiKey = "AAAAAAAAAAAAA"
$orgUrl = "https://yyyyyy.okta.com"
$groupId = "xxxxxxxxxxxxxxx"
$headers = @{
Authorization = "SSWS $apiKey"
ContentType = "application/json"
}
$url = "$orgUrl/api/v1/users?filter=status eq " + [char]34 + "ACTIVE" + [char]34
$results = @()
do {
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
write-host $response.Count -BackgroundColor Yellow
$results += $response
$url = $response.'@odata.nextLink'
} while ($url -ne $null)
foreach ($user in $response) {
Write-Host "Processing user:" $user.profile.login
$userId = $user.id
$url2 = "$orgUrl/api/v1/users/$userId/factors"
$response2 = Invoke-RestMethod -Uri $url2 -Method Get -Headers $headers
foreach ($factor in $response2) {
if ($factor.factorType -ne "token:software:totp") {
Write-Host "User:" $user.profile.login
$url3 = "$orgUrl/api/v1/groups/$groupId/users/$userId"
*Invoke-RestMethod -Uri $url3 -Method Put -Headers $headers
Write-Host "User:" $user.profile.login "has been added to group."
}
}
}

Hi @SebastienU.52034 (Customer) , Thank you for reaching out to the Okta Community!
This is limited by design to a maximum of 200.
Please see the following doc for reference
https://developer.okta.com/docs/reference/api/users/#request-parameters-3 - see "limit"
and a previous post discussing a similar topic.
https://support.okta.com/help/s/question/0D51Y000091JQ3eSAG/list-users-via-api-returns-up-to-200-users?language=en_US
If my answer helped, remember to mark it as best to increase its visibility for other members of the Okta Community who might have the same questions as you.
Hope my answer helps!
--------------------------------
Community members help others by clicking Like or Select as Best on responses. Try it today.