GtmToolFinder.psm1

Set-StrictMode -Version Latest

$script:BaseUrl = 'https://gtm-tool-finder-api.jaizendra.workers.dev'

function Get-GtmToolFinderUrl {
    <#
    .SYNOPSIS
    Builds the request URL for a search of the GTM Tool Finder API.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0)][string]$Query,
        [ValidateSet('', 'tool', 'category', 'comparison', 'glossary')][string]$Kind = '',
        [int]$Limit = 10,
        [string]$BaseUrl = $script:BaseUrl
    )
    $url = '{0}/tools?q={1}' -f $BaseUrl.TrimEnd('/'), [uri]::EscapeDataString($Query)
    if ($Kind) { $url += '&kind=' + [uri]::EscapeDataString($Kind) }
    if ($Limit -gt 0) { $url += '&limit=' + $Limit }
    $url
}

function Search-GtmTool {
    <#
    .SYNOPSIS
    Searches the free OneGTMLab GTM tool directory (tool API reviews, comparisons, glossary terms).
    .DESCRIPTION
    Calls the public, read-only GTM Tool Finder API. No API key and no sign-up. Directory: https://www.onegtmlab.dev/tool-directory
    .EXAMPLE
    Search-GtmTool 'email verification' -Kind tool -Limit 3
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0)][string]$Query,
        [ValidateSet('', 'tool', 'category', 'comparison', 'glossary')][string]$Kind = '',
        [int]$Limit = 10,
        [string]$BaseUrl = $script:BaseUrl
    )
    $url = Get-GtmToolFinderUrl -Query $Query -Kind $Kind -Limit $Limit -BaseUrl $BaseUrl
    $page = Invoke-RestMethod -Uri $url -Method Get -TimeoutSec 20
    foreach ($e in $page.data) {
        [pscustomobject]@{
            Kind        = $e.kind
            Name        = $e.name
            Category    = $e.category
            Url         = $e.url
            Description = $e.description
        }
    }
}

Export-ModuleMember -Function Get-GtmToolFinderUrl, Search-GtmTool