Skip to content

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.

  • Selling and operator tools on (API tokens card).
  • HTTPS to the panel.
  • A throwaway client you can create and delete while testing.
  1. 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.
  2. Call only the paths your job needs (list/create/renew/disable/delete clients, read usage, poll status). Prefer Clients or Read only over Full.
  3. Send Authorization: Bearer aft_… on every request. No X-Requested-With header is required for token calls.
  4. For renew and other money-moving calls, send a new Idempotency-Key per logical operation and reuse it only when retrying the same operation after a lost reply.
  5. On 429 / too_many_attempts, back off; the login guard counts bad tokens.
  6. Rotate: create a new token, switch the script, delete the old token. If a token leaked, delete it at once and see Security.

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.

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.

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.

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.