Is there any query that pull campaign reports of a targeted reviewer?

we have created citification campaigns, let say manager or app owner. Now we want pull only reports of a targeted reviewer. for example a manager campaign have different managers from that we want report to pull only one manager.

I have only been able to look up such a thing in the API’s. I have created a few PowerShell scripts to create certification reports because of trying to get data like that.

Here is an example of what I was talking about.

# Define variables
$identityNowHost = ""
$clientId = ""
$clientSecret = ""
$outputCsv = "Certifications.csv"  # Path for the output CSV file

function Get-AccessToken {
    $authUrl = "$identityNowHost/oauth/token"
    $authBody = @{
        grant_type    = "client_credentials"
        client_id     = $clientId
        client_secret = $clientSecret
    }

    Write-Host "Auth URL: $authUrl" -ForegroundColor Green

    $response = Invoke-RestMethod -Method Post -Uri $authUrl -ContentType "application/x-www-form-urlencoded" -Body $authBody
    return $response.access_token
}

# Retrieve the access token
$accessToken = Get-AccessToken

$headers = @{
    Authorization  = "Bearer $accessToken"
    "Content-Type" = "application/json"
}

# Initialize variables
$baseUrl = "$identityNowHost/v2024/certifications"
$allCertifications = @()
$hasMore = "true"
$offset = 0
$limit = 250  # Adjust as needed based on API documentation

Write-Host "Base URL: $baseUrl" -ForegroundColor Green

$url = $baseUrl + "?count=" + $hasMore

# Fetch the total count
try {

    Write-Host "Fetch Total Count URL: " + $url

    $totalCountResponse = Invoke-WebRequest -Uri $url -Method 'GET' -Headers $headers

    $totalCount = $($totalCountResponse.Headers['X-Total-Count'])
    Write-Host "Response Total: $totalCount" -ForegroundColor Cyan
}
catch {
    Write-Host "Error calling API: $($_.Exception.Message)" -ForegroundColor Red
    throw
}


while ($hasMore) {

    $url = $baseUrl + '?offset=' + $offset + '&limit=' + $limit

    # Ensure the URL is valid
    if (-not ($url -as [Uri])) {
        Write-Host "Invalid URL: $url" -ForegroundColor Red
        throw "The request URL is invalid."
    }

    # Fetch the data
    try {

        Write-Host "Fetch URL: " + $url

        $response = Invoke-RestMethod -Uri $url -Method 'GET' -Headers $headers

        Write-Host "Items Retrieved: " $($response.Count) -ForegroundColor Cyan
    }
    catch {
        Write-Host "Error calling API: $($_.Exception.Message)" -ForegroundColor Red
        throw
    }

    # Append the fetched results to the complete list
    $allCertifications += $response

    # Check if there are more items to fetch
    $hasMore = ([int]$totalCount -gt ($offset + $limit))
    Write-Host "Has More: $hasMore" -ForegroundColor Yellow
    $offset += $limit
}

# Write the results to a CSV file
$flattenedCertifications = $allCertifications | ForEach-Object {
    [PSCustomObject]@{
        ID                      = $_.id
        Created                 = $_.created
        Reviewer                = $_.reviewer.name
        Name                    = $_.campaign.name
        Description             = $_.campaign.description
        Due                     = $_.due
        SignedDate              = $_.signed
        Phase                   = $_.phase
        Modified                = $_.modified
    }
}

# Ensure we are not dealing with an empty array
if ($flattenedCertifications.Count -eq 0) {
    Write-Host "No certifications were retrieved. The CSV file will not be created." -ForegroundColor Red
}
else {
    $flattenedCertifications | Export-Csv -Path $outputCsv -NoTypeInformation
    Write-Host "Certifications data has been written to $outputCsv"
}

3 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.