Public/Get-GW2Account.ps1

<#
.SYNOPSIS
Retrieves Guild Wars 2 account information using a provided API key.
 
.DESCRIPTION
Calls the Guild Wars 2 API v2 /account endpoint and returns the deserialized account object for the API key supplied. The function issues an authenticated GET request and returns the response produced by Invoke-RestMethod.
 
.PARAMETER APIKey
The Guild Wars 2 API key (string) to authenticate the request. The key should include the appropriate scopes for account information. Keep this value secret and do not hard-code it in shared scripts.
 
.EXAMPLE
Get-GW2Account -APIKey 'your_api_key_here'
Retrieves the account object for the supplied API key.
 
.NOTES
- Requires network access to api.guildwars2.com.
- Errors such as HTTP 401/403 indicate missing/invalid scopes or an invalid key; network errors will propagate from Invoke-RestMethod.
- Ensure the API key has the necessary scope to read account information.
#>

function Get-GW2Account {
    param (
        [string]$APIKey
    )
    $headers = @{
        "Authorization" = "Bearer $APIKey"
    }
    $url = "https://api.guildwars2.com/v2/account"
    $response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
    
    return $response
}