Skip to content

Back to the cookbook

List a dashboard's version history

Lists every update (saved version) of a dashboard.

Adam Robertson Dashboards

How it works

Uses a valid access token to GET the list of dashboard updates from /{dataViewName}/Dashboards/{dashboardId}/Updates.

Before you start

You need:

This script works on its own: download it, plus Login.ps1 to get an access token.

Parameters

Parameter Description
-BaseUrl The base URL of the Orbit API, for example https://example.com/OrbitAPI
-DataViewName The name of the DataView to act on, for example holidays
-AccessToken A valid access token (gained from the Login.ps1 script) to authenticate with.
-DashboardId The ID of the dashboard to retrieve updates for.

Example

PowerShell
.\ListDashboardUpdates.ps1 `
    -BaseUrl "https://example.com/OrbitAPI" `
    -DataViewName "holidays" `
    -AccessToken "your_access_token_here" `
    -DashboardId 1234

Script

The script from the repository at commit b732915. Its built-in help is left out here, because this page shows it above. The download and the copy on GitHub include it.

Warning

Apteco provides these scripts as examples only. They're not officially supported. Review each script and test it on a non-production system before you run it against live data.

PowerShell
[CmdletBinding()]
param (
    [Parameter(Mandatory = $true)]
    [string]$BaseUrl,

    [Parameter(Mandatory = $true)]
    [string]$DataViewName,

    [Parameter(Mandatory = $true)]
    [string]$AccessToken,

    [Parameter(Mandatory = $true)]
    [int]$DashboardId
)

# ---------------------------------------------------------------------------
# Helper: exit with a clear error message
# ---------------------------------------------------------------------------
function Stop-WithError {
    param([string]$Message)
    Write-Error $Message
    exit 1
}

# ---------------------------------------------------------------------------
# Get the list of dashboard updates
# ---------------------------------------------------------------------------
$dashboardUpdatesUrl  = "$BaseUrl/$DataViewName/Dashboards/$DashboardId/Updates"

Write-Host "Getting dashboard updates for dashboard $DashboardId..." -ForegroundColor Cyan

$headers = @{
    Authorization = "Bearer $AccessToken"
}

$pageSize = 100
$offset = 0
$totalCount = 0
do
{
    try {
        $dashboardUpdatesResponse = Invoke-RestMethod `
            -Uri         "$($dashboardUpdatesUrl)?offset=$offset&count=$pageSize" `
            -Method      GET `
            -ContentType 'application/json' `
            -Headers     $headers `
            -ErrorAction Stop
    }
    catch {
        $statusCode = if ($_.Exception.Response) { $_.Exception.Response.StatusCode.value__ } else { $null }
        $errorBody  = if ($_.ErrorDetails) { $_.ErrorDetails.Message } else { $null }
        Stop-WithError "Dashboard Updates GET failed (HTTP $statusCode). Response: $errorBody`nError: $_"
    }

    $page = @($dashboardUpdatesResponse.list)
    foreach ($dashboardUpdate in $page) {
        Write-Output "$($dashboardUpdate.timestamp) (update $($dashboardUpdate.id)): Dashboard '$($dashboardUpdate.title)' updated by $($dashboardUpdate.user.username)"
    }

    $offset += $pageSize
    $totalCount += $page.Count
}
while ($page.Count -gt 0)

Write-Host "Got $totalCount dashboard updates" -ForegroundColor Green

Back to the cookbook