Public/Get-GW2Stories.ps1
|
<#
.SYNOPSIS Retrieves stories from the Guild Wars 2 API. .DESCRIPTION The Get-GW2Stories cmdlet retrieves information about stories in the Story Journal from the Guild Wars 2 API. .PARAMETER Ids The ID(s) of the stories to retrieve. Can be a single ID, an array of IDs, or "all". .PARAMETER Page The page number to retrieve. .PARAMETER PageSize The number of results per page. .PARAMETER Lang The language to return localized text in. Defaults to "en". Valid values: "en", "es", "de", "fr", "zh". .EXAMPLE Get-GW2Stories -Ids 1 Retrieves information for the story with ID 1. .EXAMPLE Get-GW2Stories -Ids "all" Retrieves information for all stories. .NOTES API Endpoint: /v2/stories #> function Get-GW2Stories { [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [string[]]$Ids, [Parameter(Mandatory = $false)] [int]$Page, [Parameter(Mandatory = $false)] [int]$PageSize, [Parameter(Mandatory = $false)] [ValidateSet("en", "es", "de", "fr", "zh")] [string]$Lang ) $Uri = "https://api.guildwars2.com/v2/stories" if ($Ids) { $Uri += "?ids=" + ($Ids -join ",") } if ($Page) { $Uri += "&page=$Page" } if ($PageSize) { $Uri += "&page_size=$PageSize" } if ($Lang) { $Uri += "&lang=$Lang" } try { Invoke-RestMethod -Uri $Uri -Method Get } catch { Write-Error "Failed to retrieve stories: $_" } } |