Transfer a dashboard to another user
Transfers the ownership of a dashboard to another user.
How it works
Uses a valid access token to transfer the ownership of a dashboard to another user via /{dataViewName}/Dashboards/{dashboardId}/TransferOwnership.
Before you start
You need:
- The base URL of the Orbit API (see Find your API URLs)
- An access token, from Log in and get an access token
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:// |
-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 transfer ownership for. |
-NewOwner |
The username of the new owner of the dashboard. |
Example
PowerShell
.\TransferDashboard.ps1 `
-BaseUrl "https://example.com/OrbitAPI" `
-DataViewName "holidays" `
-AccessToken "your_access_token_here" `
-DashboardId 1234 `
-NewOwner "new_owner_username"
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,
[Parameter(Mandatory = $true)]
[string]$NewOwner
)
# ---------------------------------------------------------------------------
# Helper: exit with a clear error message
# ---------------------------------------------------------------------------
function Stop-WithError {
param([string]$Message)
Write-Error $Message
exit 1
}
# ---------------------------------------------------------------------------
# Transfer ownership of a specific dashboard
# ---------------------------------------------------------------------------
$dashboardTransferUrl = "$BaseUrl/$DataViewName/Dashboards/$DashboardId/TransferOwnership"
Write-Host "Transferring ownership of dashboard $DashboardId to $NewOwner..." -ForegroundColor Cyan
$headers = @{
Authorization = "Bearer $AccessToken"
}
$transferDashboardBody = @{
newUsername = $NewOwner
}
$transferDashboardJson = $transferDashboardBody | ConvertTo-Json
try {
$dashboardResponse = Invoke-RestMethod `
-Uri "$($dashboardTransferUrl)?newOwner=$NewOwner" `
-Method POST `
-ContentType 'application/json; charset=utf-8' `
-Headers $headers `
-Body $transferDashboardJson `
-ErrorAction Stop
}
catch {
$statusCode = if ($_.Exception.Response) { $_.Exception.Response.StatusCode.value__ } else { $null }
$errorBody = if ($_.ErrorDetails) { $_.ErrorDetails.Message } else { $null }
Stop-WithError "Dashboard Transfer POST failed (HTTP $statusCode). Response: $errorBody`nError: $_"
}
Write-Host "Transferred ownership of dashboard $($DashboardId) to $($NewOwner)" -ForegroundColor Green