-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListTableDefinitions.ps1
More file actions
89 lines (71 loc) · 2.51 KB
/
ListTableDefinitions.ps1
File metadata and controls
89 lines (71 loc) · 2.51 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
82
83
84
85
86
87
88
89
<#
.SYNOPSIS
Lists all user-defined table definitions in a DataView.
.DESCRIPTION
Uses a valid access token to GET the list of user-defined table definitions
from /{dataViewName}/TableDefinitions.
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.
.EXAMPLE
.\ListTableDefinitions.ps1 `
-BaseUrl "https://example.com/holidays/OrbitConnectAPI" `
-DataViewName "holidays" `
-AccessToken "your_access_token_here"
#>
[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