>-
This skill is the single source of truth for both. Other skills (`sending-emails`, `testing-with-sandbox`, `using-email-templates`, `managing-contacts`, `setting-up-sending-domain`) reference these conventions instead of duplicating them.
The 1,031-word prompt provides structured testing & qa guidance — covering detailed methodology and consistent output formats. Paste it into your CLAUDE.md or .cursorrules to activate.
Every Mailtrap API request needs two things:
account_id in the URL path.sending-emails, testing-with-sandbox, using-email-templates, managing-contacts, setting-up-sending-domain) reference these conventions instead of duplicating them.account_id for an account-scoped endpoint401 Unauthorized / 403 Forbidden responsesCreate tokens at Settings > [API Tokens](https://mailtrap.io/api-tokens) with the smallest scope that works:
send.api.mailtrap.io and bulk.api.mailtrap.io. Scope per stream (transactional, bulk) when possible.sandbox.api.mailtrap.io). Always separate from live sending tokens.https://mailtrap.io/api/accounts/{account_id}/....Mailtrap accepts either header. Use Bearer in examples — it's the more common HTTP convention and matches most generated SDK code.
| Form | Header | When to use |
| ------------------- | -------------------------------------------- | -------------------------------------------- |
| Bearer (preferred) | Authorization: Bearer $MAILTRAP_API_TOKEN | Default for new code, SDKs, curl examples |
| Api-Token (legacy) | Api-Token: $MAILTRAP_API_TOKEN | Older clients or where Bearer is awkward |
Do not send both at the same time. The same value goes in either header.
.env file that is in .gitignore. Load with direnv, dotenv, or the framework's built-in mechanism.ps, and CI logs.$VAR_NAME shell-var placeholders in all examples so generated code reaches for the env var, not the literal.These names are used consistently across every other skill in this repo and across the example snippets below.
| Variable | Used for |
| ---------------------------- | -------------------------------------------------------------------------------------- |
| MAILTRAP_API_TOKEN | General API: Email Send (transactional and bulk), Templates, Contacts, Sending Domains, Suppressions |
| MAILTRAP_SANDBOX_API_TOKEN | Sandbox / Email Testing (separate scope) |
| MAILTRAP_ACCOUNT_ID | Path parameter for account-scoped endpoints |
If your environment uses different names, alias them once at startup so the examples in other skills work unchanged.
account_id automaticallyaccount_id is the integer prefix on every https://mailtrap.io/api/accounts/{account_id}/... endpoint. Do not hardcode it. It changes between environments, is different per organization, and is silently wrong when you copy a script to a teammate's account.
Resolve it once per session from the Accounts endpoint, which lists every account the token can access:
curl -s https://mailtrap.io/api/accounts \
-H "Authorization: Bearer $MAILTRAP_API_TOKEN"Response shape (array):
[
{"id": 12345, "name": "My Company", "access_levels": [1000]},
{"id": 67890, "name": "Client Account", "access_levels": [100]}
]access_levels values:
1000 — Account owner100 — Admin10 — Viewer (read-only on most endpoints)export MAILTRAP_ACCOUNT_ID=$(curl -s https://mailtrap.io/api/accounts \
-H "Authorization: Bearer $MAILTRAP_API_TOKEN" | jq '.[0].id')Reference: [Accounts API](https://docs.mailtrap.io/developers/account-management/accounts).
# Live sending (no account_id in path)
curl -X POST https://send.api.mailtrap.io/api/send \
-H "Authorization: Bearer $MAILTRAP_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{ ... }'# Account-scoped endpoint
curl "https://mailtrap.io/api/accounts/$MAILTRAP_ACCOUNT_ID/contacts/lists" \
-H "Authorization: Bearer $MAILTRAP_API_TOKEN"
# Sandbox / Testing
curl -X POST "https://sandbox.api.mailtrap.io/api/send/$MAILTRAP_INBOX_ID" \
-H "Authorization: Bearer $MAILTRAP_SANDBOX_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{ ... }'
| Mistake | Fix |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| Hardcoding the token in code, config, or a notebook | Load from $MAILTRAP_API_TOKEN (env, .env, CI secret, secret manager); rotate the token if it ever leaked |
| Passing the token as a CLI flag (--token=...) | Use env vars; CLI flags leak to shell history, ps, and CI logs |
| Committing a token, then deleting it in a later commit | History keeps the value forever — rotate the token immediately, do not just remove the file |
| Pasting a token into chat / prompt / issue | Treat chat as public; rotate if it happened |
| Using the live MAILTRAP_API_TOKEN against the sandbox host | Sandbox uses its own scope and MAILTRAP_SANDBOX_API_TOKEN; mixing them either fails or sends real mail by accident |
| Hardcoding account_id | Resolve via GET https://mailtrap.io/api/accounts once per run and pass through $MAILTRAP_ACCOUNT_ID |
| Picking the wrong account when the token can see several | Filter the GET /api/accounts response by name or access_levels (1000 = owner) instead of .[0] |
| Sending both Authorization and Api-Token headers | Pick one (Bearer for new code); duplicating them is unnecessary and confuses some intermediaries |
| Using a viewer-scoped token for writes | Check access_levels; writes need 100 (admin) or 1000 (owner) for the relevant account |
Authorizing Api Requests is a free testing & qa skill for AI coding agents. >-. It provides a specialized system prompt that configures your agent with testing & qa expertise.
Copy the system prompt below and paste it into your CLAUDE.md file or Claude Code's custom instructions to activate Authorizing Api Requests.
Authorizing Api Requests is compatible with Claude Code, Cursor, GitHub Copilot, Windsurf, OpenClaw, Cline, and any AI agent that supports custom system prompts or .cursorrules files.
Yes, Authorizing Api Requests is completely free and open source. The full source is available on GitHub at https://github.com/mailtrap/mailtrap-skills/blob/main/skills/authorizing-api-requests/SKILL.md. You only need a subscription to the AI agent you use it with.
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.