Public/Get-ConnectorData.ps1

<#
.SYNOPSIS
    Retrieves all connector objects from the Fortytwo IAM Core Connector API.

.DESCRIPTION
    Fetches the full set of connector objects currently stored in the Fortytwo IAM platform
    for the connected connector. Requires an active connection established by Connect-Connector.

.OUTPUTS
    System.Object[]

.EXAMPLE
    $data = Get-ConnectorData
#>

function Get-ConnectorData {
    [CmdletBinding()]
    param ()

    if([String]::IsNullOrEmpty($Script:APIRoot)) {
        throw "Please connect first"
    }

    Write-Verbose "Fetching connector data from API"
    $result = Invoke-RestMethod -Uri "$($Script:APIRoot)data" -Headers (Get-EntraIDAccessTokenHeader -Profile $Script:AccessTokenProfile) -Method Get -SkipHttpErrorCheck
    
    if ($result.IsSuccess) {
        $result.Data
    }
    else {
        throw "Failed to retrieve connector data. Status code: $($result.StatusCode). Response: $($result.ErrorMessage)"
    }
}