Modules/businessdev.ALbuild.Marketplace/Public/Get-BcMarketplaceProduct.ps1

function Get-BcMarketplaceProduct {
    <#
    .SYNOPSIS
        Retrieves Business Central products from the Microsoft product-ingestion API.
 
    .PARAMETER AuthContext
        An auth context from New-BcMarketplaceAuthContext (Graph scope:
        'https://graph.microsoft.com/.default').
 
    .PARAMETER Name
        Optional name filter (substring match).
 
    .PARAMETER ProductType
        Product type. Default 'dynamics-365-business-central'.
 
    .PARAMETER ApiVersion
        Product ingestion API version. Default '2023-07-01'.
 
    .OUTPUTS
        The product object(s).
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)] [PSCustomObject] $AuthContext,
        [string] $Name,
        [string] $ProductType = 'dynamics-365-business-central',
        [string] $ApiVersion = '2023-07-01'
    )

    $headers = @{ Authorization = "Bearer $($AuthContext.AccessToken)" }
    $url = "https://graph.microsoft.com/rp/product-ingestion/product?type=$ProductType&`$version=$ApiVersion"
    $response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get -ErrorAction Stop

    $products = @($response.value)
    if ($Name) { $products = @($products | Where-Object { $_.name -like "*$Name*" }) }
    return $products
}