Public/Get-GW2Achievements.ps1

<#
.SYNOPSIS
Retrieves achievement details from the Guild Wars 2 API.
 
.DESCRIPTION
Calls the Guild Wars 2 API v2 /achievements endpoint.
- If no parameters are provided, returns a list of all achievement IDs.
- If 'Ids' is provided, returns objects containing details for the specified achievements.
 
.PARAMETER Ids
Optional. An array of integers or strings representing achievement IDs.
Example: 1, 100, 200
 
.PARAMETER lang
Optional. A string representing the language to use for achievement names and descriptions.
Example: en, de, fr, ja, ko, zh
 
.EXAMPLE
Get-GW2Achievements
Returns a list of all achievement IDs.
 
.EXAMPLE
Get-GW2Achievements -Ids 1840, 910
Returns details for the specified achievements.
 
.NOTES
- Requires network access to api.guildwars2.com.
- This is a public endpoint and does not require an API key.
#>

function Get-GW2Achievements {
    param (
        [Parameter(Mandatory = $false)]
        [int[]]$Ids,
        [Parameter(Mandatory = $false)]
        [ValidateSet("en", "de", "fr", "ja", "ko", "zh")]
        [string]$Lang
    )
    
    $url = "https://api.guildwars2.com/v2/achievements"

    if ($Ids) {
        # Join IDs with commas for the query parameter
        $idString = $Ids -join ','
        $url = $url + "?ids=$idString"
    }
    if ($Lang) {
        $url = $url + "&lang=$Lang"
    }
    write-host $url
    $response = Invoke-RestMethod -Uri $url -Method Get
    
    return $response
}