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 {
            throw "Failed to get Collections Tenant Schema: $($Result.Errors -join '; ')"
        }
    }
}