Use the API from a script
Scripts should use API tokens, not a stolen browser cookie. This guide is the safe subset; the API page has the curl examples for clients.
Before you start
Section titled “Before you start”- Selling and operator tools on (API tokens card).
- HTTPS to the panel.
- A throwaway client you can create and delete while testing.
- In Settings → Security → API tokens, create a token with the smallest access that works (Clients for billing bots, Read only for monitors). Copy it once.
- Call only the paths your job needs (list/create/renew/disable/delete clients, read usage, poll status). Prefer Clients or Read only over Full.
- Send
Authorization: Bearer aft_…on every request. NoX-Requested-Withheader is required for token calls. - For renew and other money-moving calls, send a new
Idempotency-Keyper logical operation and reuse it only when retrying the same operation after a lost reply. - On
429/too_many_attempts, back off; the login guard counts bad tokens. - Rotate: create a new token, switch the script, delete the old token. If a token leaked, delete it at once and see Security.
What a token can never do
Section titled “What a token can never do”Password change, two-factor, creating tokens, backups, restore, update install, AmneziaWG install, compromised, factory reset, and bridge/exit/server install commands that carry join secrets. Those answer session_only and need a signed-in admin.
How to check it worked
Section titled “How to check it worked”Your script creates a client, reads GET clients/ID/config, renews, then deletes. Activity log shows token:NAME. Monitor scrapes GET status or GET metrics with Read only.
If it does not
Section titled “If it does not”token_scope — wrong access. session_only — that call is not for tokens. csrf — you used a browser cookie without X-Requested-With: aftab. See API.
What is not changed
Section titled “What is not changed”This guide does not publish a full call list. For any other call, use the panel’s Network tab on the page that does it.