Public/Get-CollectionTenantSchema.ps1

<#
.SYNOPSIS
    Gets the collections tenant schema from the Fortytwo Collections API.

.DESCRIPTION
    This function retrieves the collections tenant schema from the Fortytwo Collections API.
#>

function Get-CollectionTenantSchema {
    [CmdletBinding(DefaultParameterSetName = "Default")]
    param ()

    process {
        if (-not $Script:APIRoot -or -not $Script:AccessTokenProfile) {
            throw "Not connected to Fortytwo Collections. Please run Connect-Collections first."
        }

        $Uri = ($Script:APIRoot -f "collections-criteria", "/tenant-schemas")

        Write-Verbose "Getting Collections Tenant Schema from URI: $Uri"
        $Result = Invoke-RestMethod -Uri $Uri -Headers (Get-CollectionHeader) -SkipHttpErrorCheck -StatusCodeVariable StatusCode -Verbose:$false -ConnectionTimeoutSeconds 60 -OperationTimeoutSeconds 60

        if ($Result.IsSuccess) {
            return $Result.Data
        }
        else {
            if (!$Result.Errors) {
                if ($StatusCode -eq 403) {
                    throw "Access denied. Please ensure that your access token has the necessary permissions to access Fortytwo Collections."
                }
                else {
                    throw "Failed to get Fortytwo Collections objects. StatusCode: $StatusCode"
                }
            }
            throw $($Result.Errors -join '; ')
        }
    }
}