Create a dashboard theme
Creates a dashboard theme from a JSON definition file.
How it works
Uses a valid access token to POST a JSON file to /{dataViewName}/Themes.
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
- An Orbit user with the OrbitAdmin role
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. |
-ThemeJsonPath |
The path to the JSON file to post to the Themes endpoint. |
Example
PowerShell
.\CreateDashboardTheme.ps1 `
-BaseUrl "https://example.com/OrbitAPI" `
-DataViewName "holidays" `
-AccessToken "your_access_token_here" `
-ThemeJsonPath ".\theme.json"
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)]
[string]$ThemeJsonPath
)
# ---------------------------------------------------------------------------
# Helper: exit with a clear error message
# ---------------------------------------------------------------------------
function Stop-WithError {
param([string]$Message)
Write-Error $Message
exit 1
}
# ---------------------------------------------------------------------------
# Validate the theme JSON file exists
# ---------------------------------------------------------------------------
if (-not (Test-Path -Path $ThemeJsonPath -PathType Leaf)) {
Stop-WithError "Theme JSON file not found: $ThemeJsonPath"
}
# ---------------------------------------------------------------------------
# Post the theme JSON
# ---------------------------------------------------------------------------
$themeUrl = "$BaseUrl/$DataViewName/Themes"
$themeJson = Get-Content -Path $ThemeJsonPath -Raw -Encoding UTF8
Write-Host "Posting theme JSON from '$ThemeJsonPath' to '$themeUrl'..." -ForegroundColor Cyan
$headers = @{
Authorization = "Bearer $AccessToken"
}
try {
$themeResponse = Invoke-RestMethod `
-Uri $themeUrl `
-Method POST `
-ContentType 'application/json; charset=utf-8' `
-Headers $headers `
-Body $themeJson `
-ErrorAction Stop
}
catch {
$statusCode = if ($_.Exception.Response) { $_.Exception.Response.StatusCode.value__ } else { $null }
$errorBody = if ($_.ErrorDetails) { $_.ErrorDetails.Message } else { $null }
Stop-WithError "Theme POST failed (HTTP $statusCode). Response: $errorBody`nError: $_"
}
Write-Host "Theme $($themeResponse.name) (ID: $($themeResponse.id)) created successfully!" -ForegroundColor Green