Public/Get-BBUserRole.ps1

Function Get-BBUserRole {
    <#
    .SYNOPSIS
        Get the list of userroles as they are known in the GoBright API
    .DESCRIPTION
        Get the list of userroles as they are known in the GoBright API
    .PARAMETER BrightBookingApiUrl
        Address of the GoBright API, e.g.: https://t1b.gobright.cloud/ (please get this from the 'General Settings' page of the portal)
    .PARAMETER BrightBookingApiToken
        A valid token to access the api
    .EXAMPLE
        Get-BBUserRole -BrightBookingApiUrl "https://t1b.gobright.cloud/" -BrightBookingApiToken "[already retreived api token]"
    .LINK
        https://support.gobright.com/
    #>


    [CmdletBinding()]
    Param(
      [Parameter(Mandatory=$True)]
       [string]$BrightBookingApiUrl,

      [Parameter(Mandatory=$True)]
       [string]$BrightBookingApiToken
    )
    Process {
        $pathandquery = "/api/user-roles/sync";

        $resturi = [System.Uri]::new([System.Uri]::new($BrightBookingApiUrl), $pathandquery)
        
        $hdrs = @{}
        $hdrs.Add("Authorization", "Bearer "+ $BrightBookingApiToken)

        Try
        {
            $response = Invoke-WebRequest -TimeoutSec 1200 -Uri $resturi -Method Get -Headers $hdrs -UseBasicParsing
        
            If ($response.StatusCode -eq 200 -or $response.StatusCode -eq 201)
            {
                $jsonresponse = $response.Content | ConvertFrom-Json
            } else {
                throw "Failed to get user sync status from the API. (statuscode: $response.StatusCode)"
            }
        }
        Catch 
        {
            $statusCode = $_.Exception.Response.StatusCode.Value__
            $responseText = $_
                        
            Try
            {
                $jsonresponse = $responseText | ConvertFrom-Json
                If ($jsonresponse.SyncRoot)
                {
                    $statusMessage = $jsonresponse.SyncRoot
                }
                Else
                {
                    $statusMessage = $responseText
                }
            } 
            Catch 
            {
                $statusMessage = $responseText
            }
            
            throw "Failed to get user sync status from the API. (statuscode: $statusCode, message: $statusMessage)"
        }
        
        return $jsonresponse
    }
}