Functions/Get-ClientOverview.ps1

function Get-ClientOverview {
    <#
    .SYNOPSIS
        Retrieves a complete overview of a specific client from the Gorelo API.
 
    .DESCRIPTION
        Combines related data for a single client, including:
          - Client information
          - Assets
          - Locations
          - Domains
          - Contacts
        (Invoices are intentionally excluded.)
 
        This function leverages other Gorelo module cmdlets:
          Get-Clients, Get-Assets, Get-Locations, Get-Domains, Get-Contacts
 
    .PARAMETER BaseUrl
        Base API URL (default: https://api.usw.gorelo.io)
 
    .PARAMETER ApiVersion
        API version (default: v1)
 
    .PARAMETER ApiKey
        API key for authentication.
 
    .PARAMETER ClientId
        The unique ID of the client to retrieve information for.
 
    .EXAMPLE
        Get-ClientOverview -ApiKey $APIKey -ClientId 'xxx' # Retrieves all data for that client
 
    .NOTES
        Author: Gorelo Module
        Retrieves: Client, Assets, Locations, Domains, Contacts
        Excludes: Invoices
    #>


    [CmdletBinding()]
    param(
        [string]$BaseUrl     = "https://api.usw.gorelo.io",
        [string]$ApiVersion  = "v1",

        [Parameter(Mandatory = $true)]
        [string]$ApiKey,

        [Parameter(Mandatory = $true)]
        [string]$ClientId
    )

    Write-Verbose "Building client overview for ClientId: $ClientId"

    # --- Retrieve client details ---
    try {
        $client = Get-Clients -ApiKey $ApiKey -BaseUrl $BaseUrl -ApiVersion $ApiVersion -ID $ClientId -ErrorAction Stop
    }
    catch {
        throw "Failed to retrieve client $ClientId : $($_.Exception.Message)"
    }

    # --- Retrieve related entities ---
    try {
        $assets    = Get-Assets    -ApiKey $ApiKey -BaseUrl $BaseUrl -ApiVersion $ApiVersion -ClientID $ClientId -ErrorAction SilentlyContinue
        $locations = Get-Locations -ApiKey $ApiKey -BaseUrl $BaseUrl -ApiVersion $ApiVersion -ClientId $ClientId -ErrorAction SilentlyContinue
        $domains   = Get-Domains   -ApiKey $ApiKey -BaseUrl $BaseUrl -ApiVersion $ApiVersion -ClientId $ClientId -ErrorAction SilentlyContinue
        $contacts  = Get-Contacts  -ApiKey $ApiKey -BaseUrl $BaseUrl -ApiVersion $ApiVersion -ClientId $ClientId -ErrorAction SilentlyContinue
    }
    catch {
        Write-Warning "Some related data could not be retrieved: $($_.Exception.Message)"
    }

    # --- Build structured overview object ---
    $overview = [PSCustomObject]@{
        Client    = $client
        Assets    = if ($assets) { $assets } else { @() }
        Locations = if ($locations) { $locations } else { @() }
        Domains   = if ($domains) { $domains } else { @() }
        Contacts  = if ($contacts) { $contacts } else { @() }
        Retrieved = (Get-Date)
    }

    return $overview
}


<#
 
$APIKey = 'xxx'
 
Get-ClientOverview -ApiKey $APIKey -ClientId "xxx" # Gets AllClientInfo by ClientID
 
#>