The agent that turns websites into APIs!
Generate a PowerShell module that replicates the API calls found in the traffic. The following are guidelines — use your judgment on what's appropriate for the specific API:
- Target PowerShell 7+ (
pwsh), not Windows PowerShell 5.1. Do not use Windows-only cmdlets orSystem.Webtypes that require .NET Framework - Module file is a single
.psm1with one or more advanced functions. Every public function:- Uses an approved verb (
Get-Verblist) —Get-,Invoke-,New-,Set-,Remove-, etc. Never invent unapproved verbs likeFetch-orDo- - Has
[CmdletBinding()]and typed[Parameter()]blocks (mandatory/optional,[string],[hashtable],[switch]etc. — no untyped params) - Is exported explicitly via
Export-ModuleMember -Function <Name>at the bottom of the file. Do not use wildcard export (Export-ModuleMember -Function *)
- Uses an approved verb (
- HTTP calls use
Invoke-RestMethod(orInvoke-WebRequestonly when raw headers/status codes are needed). Never shell out tocurl.exeorcurl - Session/cookie handling: use
-SessionVariable/-WebSessionwith[Microsoft.PowerShell.Commands.WebRequestSession], not manual cookie header construction, unless the API requires a cookie value that PowerShell's cookie jar can't express - Error handling: every network call wrapped in a
try/catchblock with-ErrorAction Stopon the call itself. Catch blocks should surface$_.Exception.Messageand, where the failure is an HTTP error, the response body if retrievable, then rethrow withthrow; never swallow the error or only callWrite-Errorand continue - Use
[PSCustomObject]for structured return values, not raw hashtables, so downstreamConvertTo-Jsonand property access behave predictably - Prefer
ConvertTo-Json/ConvertFrom-Json(built-in) over any third-party JSON handling - No
Write-Hostfor data output — useWrite-Output/return values.Write-Verbose/Write-Errorare fine for diagnostics - Create a separate exported function for each distinct API endpoint
Authentication & credentials:
- Hardcode all cookies, tokens, session IDs, and auth headers found in the traffic directly in the module
- The user should be able to run the example immediately with zero configuration — no env vars, no config files, no manual setup
- If the API uses cookies, populate a
WebRequestSessionwith them and reuse it across calls - If the API uses Bearer tokens or API keys, hardcode them in the request headers
- Handle auth refresh so the module doesn't go stale: if you see a token refresh endpoint, OAuth refresh flow, or login endpoint in the traffic, implement automatic re-authentication when a request returns 401/403. If cookies have expiry, re-fetch them before they expire
Testing:
- Run:
{run_command} - You have up to 5 attempts to fix issues
Save the module to: {scripts_dir}/{client_filename}
Save documentation to: {scripts_dir}/README.md
The example uses fixed demonstration arguments. CLI argument overrides are not supported; document how to edit the example or import the module and call its functions directly.
Save the example script to: {scripts_dir}/Example.ps1, which does:
$ErrorActionPreference = 'Stop'
Import-Module (Join-Path $PSScriptRoot '{client_filename}') -Force -ErrorAction Stop
# Invoke the exported function(s), using valid demonstration arguments.
# Serialize returned data with ConvertTo-Json -Depth 20.
# Let terminating errors propagate so pwsh exits nonzero on failure.
Do not generate a .psd1 module manifest.