Trying to build one using CHAT GPT now. Just can’t figure out one issue currently which is adding in
the filters because the inverted comas are disrupting the flow is what I believe. Its coming up with an unexpected token error for the Source ID eq part. And not sure how to overcome it
’
Define the base URL of the API and the endpoint to be queried
$baseUrl = “https://tenant.api.identitynow.com/v3/accounts?filters=sourceid eq”
$endpoint = “/items”
Define the URL to retrieve the JWT token from
$jwtUrl = “https://tenant.identitynow.com/ui/session/get-jwt”
Retrieve the JWT token from the URL
$jwtToken = Invoke-RestMethod -Method Get -Uri $jwtUrl -ContentType “application/json”
Define the source ID
$sourceId = “2c9180867a15f0f1017a1f6580392a5f”
Construct the full base URL with the source ID
$fullBaseUrl = “$baseUrl "$sourceId"”
Define the offset value
$offset = 0
Define the maximum number of results to retrieve in each iteration
$limit = 250
Set a flag to determine when to stop the loop
$moreResults = $true
Create an empty array to store the results
$results = @()
Start a loop to retrieve the results in chunks of 250
while ($moreResults) {
Construct the full API URL with the offset and limit parameters
$apiUrl = “$fullBaseUrl$endpoint?offset=$offset&limit=$limit”
Set the Authorization header with the JWT token
$headers = @{
“Authorization” = “Bearer $jwtToken”
}
Make the API request and store the response in a variable
$response = Invoke-RestMethod -Method Get -Uri $apiUrl -Headers $headers -ContentType “application/json”
Check if there are more results to retrieve
if ($response.total -le $offset + $limit) {
$moreResults = $false
}
Add the results to the array
$results += $response.items
Increment the offset value
$offset += $limit
}
Do something with the final array of results
$results | ForEach-Object
’