Public/Get-GW2PvPGames.ps1
|
<#
.SYNOPSIS Retrieves the account's PvP games using a provided API key. .DESCRIPTION Calls the Guild Wars 2 API v2 /account/pvp/games endpoint and returns the deserialized object containing the account's PvP games. The function issues an authenticated GET request. .PARAMETER APIKey The Guild Wars 2 API key (string) to authenticate the request. Requires 'account' and 'progression' scopes. .PARAMETER GameIDs A list of IDs (string array) of the PvP games to retrieve. If not specified, all PvP games will be retrieved. .EXAMPLE Get-GW2PvPGames -APIKey 'your_api_key_here' .NOTES - Requires network access to api.guildwars2.com. - Ensure the API key has the necessary scopes. #> function Get-GW2PvPGames { param ( [string]$APIKey, [Parameter(Mandatory = $false)] [string[]]$GameIDs ) $headers = @{ "Authorization" = "Bearer $APIKey" } $url = "https://api.guildwars2.com/v2/pvp/games" If ($GameIDs) { $url += "?ids=" + ($GameIDs -join ",") } $response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers return $response } |