List Connect table definitions
Lists all user-defined table definitions in a DataView.
How it works
Uses a valid access token to GET the list of user-defined table definitions from /{dataViewName}/TableDefinitions. Requires the OrbitAdmin role.
Before you start
You need:
- The base URL of the Connect 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 Connect 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. |
Example
PowerShell
.\ListTableDefinitions.ps1 `
-BaseUrl "https://example.com/OrbitConnectAPI" `
-DataViewName "holidays" `
-AccessToken "your_access_token_here"
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
)
# ---------------------------------------------------------------------------
# Helper: exit with a clear error message
# ---------------------------------------------------------------------------
function Stop-WithError {
param([string]$Message)
Write-Error $Message
exit 1
}
# ---------------------------------------------------------------------------
# Get the list of table definitions (paged)
# ---------------------------------------------------------------------------
$tableDefinitionsUrl = "$BaseUrl/$DataViewName/TableDefinitions"
$headers = @{
Authorization = "Bearer $AccessToken"
}
Write-Host "Getting table definitions..." -ForegroundColor Cyan
$pageSize = 100
$offset = 0
$totalCount = 0
do {
$uri = "${tableDefinitionsUrl}?offset=$offset&count=$pageSize"
try {
$response = Invoke-RestMethod `
-Uri $uri `
-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 "TableDefinitions GET failed (HTTP $statusCode). Response: $errorBody`nError: $_"
}
$page = @($response.list)
foreach ($item in $page) {
Write-Output "$($item.id): $($item.title)"
}
$offset += $pageSize
$totalCount += $page.Count
}
while ($page.Count -gt 0)
Write-Host "Got $totalCount table definitions" -ForegroundColor Green