Public/Get-GW2Traits.ps1
|
<#
.SYNOPSIS Retrieves trait information from the Guild Wars 2 API. .DESCRIPTION Calls the Guild Wars 2 API v2 /traits endpoint. - If no parameters are provided, returns a list of all available trait IDs. - If 'Ids' is provided, returns objects containing details for the specified traits. - If 'All' is specified, returns all available traits. .PARAMETER Ids Optional. A list of trait IDs (integers) to retrieve. Example: 1, 214 .PARAMETER All Optional. If set, retrieves all traits. .PARAMETER Lang Optional. The language to return results in (en, es, de, fr, ko, zh). .EXAMPLE Get-GW2Traits Returns a list of all trait IDs. .EXAMPLE Get-GW2Traits -Ids 214 Returns details for the specified trait. .EXAMPLE Get-GW2Traits -All Returns details for all traits. .NOTES - Requires network access to api.guildwars2.com. - This is a public endpoint and does not require an API key. #> function Get-GW2Traits { param ( [Parameter(Mandatory = $false)] [int[]]$Ids, [Parameter(Mandatory = $false)] [switch]$All, [Parameter(Mandatory = $false)] [ValidateSet("en", "es", "de", "fr", "ko", "zh")] [string]$Lang ) $url = "https://api.guildwars2.com/v2/traits" 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 } |