Public/Get-GW2Professions.ps1
|
<#
.SYNOPSIS Retrieves profession information from the Guild Wars 2 API. .DESCRIPTION Calls the Guild Wars 2 API v2 /professions endpoint. - If no parameters are provided, returns a list of all available profession IDs. - If 'Ids' is provided, returns objects containing details for the specified professions. - If 'All' is specified, returns all available professions. .PARAMETER Ids Optional. A list of profession IDs (strings) to retrieve. Example: "Necromancer", "Guardian" .PARAMETER All Optional. If set, retrieves all professions. .PARAMETER Lang Optional. The language to return results in (en, es, de, fr, ko, zh). .EXAMPLE Get-GW2Professions Returns a list of all profession IDs. .EXAMPLE Get-GW2Professions -Ids "Necromancer" Returns details for the specified profession. .EXAMPLE Get-GW2Professions -All Returns details for all professions. .NOTES - Requires network access to api.guildwars2.com. - This is a public endpoint and does not require an API key. #> function Get-GW2Professions { param ( [Parameter(Mandatory = $false)] [string[]]$Ids, [Parameter(Mandatory = $false)] [switch]$All, [Parameter(Mandatory = $false)] [ValidateSet("en", "es", "de", "fr", "ko", "zh")] [string]$Lang ) $url = "https://api.guildwars2.com/v2/professions" if ($All) { $url = $url + "?ids=all" } elseif ($Ids) { # Join IDs with commas for the query parameter $idString = $Ids -join ',' $url = $url + "?ids=$idString" } if ($Lang) { if ($url.Contains("?")) { $url = $url + "&lang=$Lang" } else { $url = $url + "?lang=$Lang" } } $response = Invoke-RestMethod -Uri $url -Method Get return $response } |