...
Code Block | ||
---|---|---|
| ||
$headers = @{
"x-api-key" = "{API KEY}"
"Content-Type" = "application/json"
}
$body = "{}"
$outputData = @()
$response = Invoke-RestMethod -Uri 'https://{BASE URL}/gytpolapi/v2.0/get_misconfigurations_start' -Method 'POST' -Headers $headers -Body $body
do {
# Convert response to JSON and output
$response | ConvertTo-Json -Depth 3
# Accumulate data for each iteration
$outputData += $response
# Prepare next request body
$body = @{ token = $response.token } | ConvertTo-Json
# Make next request
$response = Invoke-RestMethod -Uri 'https://{BASE URL}/gytpolapi/v2.0/get_misconfigurations_next' -Method 'POST' -Headers $headers -Body $body
} until ($response.computers.Count -eq 0 -or $iteration -eq 5)
# Export all the data to a JSON file
$outputData | ConvertTo-Json | Set-Content -Path "C:\path\to\output_data.json" |
...