Repository navigation
Expand file tree
/
Copy pathGetTableDefinition.ps1
More file actions
82 lines (64 loc) · 2.52 KB
/
Copy pathGetTableDefinition.ps1
File metadata and controls
82 lines (64 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<#
.SYNOPSIS
Gets a specific user-defined table definition in a DataView.
.DESCRIPTION
Uses a valid access token to GET a specific user-defined table definition from
/{dataViewName}/TableDefinitions/{tableDefinitionId}.
Requires the OrbitAdmin role.
.PARAMETER BaseUrl
The base URL of the Connect API, e.g. https://example.com/holidays/OrbitConnectAPI
.PARAMETER DataViewName
The name of the DataView to act on, e.g. "holidays"
.PARAMETER AccessToken
A valid access token (gained from the Login.ps1 script) to authenticate with.
.PARAMETER TableDefinitionId
The ID of the user-defined table definition to retrieve.
.EXAMPLE
.\GetTableDefinition.ps1 `
-BaseUrl "https://example.com/holidays/OrbitConnectAPI" `
-DataViewName "holidays" `
-AccessToken "your_access_token_here" `
-TableDefinitionId 1234
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$BaseUrl,
[Parameter(Mandatory = $true)]
[string]$DataViewName,
[Parameter(Mandatory = $true)]
[string]$AccessToken,
[Parameter(Mandatory = $true)]
[int]$TableDefinitionId
)
# ---------------------------------------------------------------------------
# Helper: exit with a clear error message
# ---------------------------------------------------------------------------
function Stop-WithError {
param([string]$Message)
Write-Error $Message
exit 1
}
# ---------------------------------------------------------------------------
# Get the table definition
# ---------------------------------------------------------------------------
$tableDefinitionUrl = "$BaseUrl/$DataViewName/TableDefinitions/$TableDefinitionId"
$headers = @{
Authorization = "Bearer $AccessToken"
}
Write-Host "Getting table definition $TableDefinitionId..." -ForegroundColor Cyan
try {
$tableDefinitionResponse = Invoke-RestMethod `
-Uri $tableDefinitionUrl `
-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 "TableDefinition $TableDefinitionId GET failed (HTTP $statusCode). Response: $errorBody`nError: $_"
}
$tableDefinitionResponse | ConvertTo-Json -Depth 100
Write-Host "Got table definition $($tableDefinitionResponse.id): $($tableDefinitionResponse.title)" -ForegroundColor Green