SKILL·8E456D

authorizing-api-requests

mailtrap
Aktualisiert 27 days ago
4 Ansichten
9
1
9
Auf GitHub ansehen
Metaaitestingapi

Über

Diese Fähigkeit bietet den maßgeblichen Leitfaden zur Authentifizierung aller Mailtrap-API-Anfragen, einschließlich Token-Auswahl, sicherer Speicherung und account_id-Auflösung. Verwenden Sie sie vor der Implementierung eines API-Aufrufs, um Autorisierungs-Header und URL-Parameter korrekt zu konfigurieren. Sie dient als zentrale Referenz, auf die sich andere Mailtrap-Fähigkeiten für Authentifizierungsmuster stützen.

Schnellinstallation

Claude Code

Empfohlen
Primär
npx skills add mailtrap/mailtrap-skills -a claude-code
Plugin-BefehlAlternativ
/plugin add https://github.com/mailtrap/mailtrap-skills
Git CloneAlternativ
git clone https://github.com/mailtrap/mailtrap-skills.git ~/.claude/skills/authorizing-api-requests

Kopieren Sie diesen Befehl und fügen Sie ihn in Claude Code ein, um diese Fähigkeit zu installieren

Dokumentation

Authorizing Mailtrap API requests

Overview

Every Mailtrap API request needs two things:

  1. An API token in an auth header — proves identity and carries the scope.
  2. For account-scoped endpoints (most of them outside of the send hosts), an account_id in the URL path.

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.

When to use

  • Before writing any Mailtrap API call from code, scripts, CI, IaC, or an AI agent
  • Picking which token scope and stream to provision
  • Deciding where to store a token (env, secret manager, CI)
  • Resolving the account_id for an account-scoped endpoint
  • Debugging 401 Unauthorized / 403 Forbidden responses

API tokens

Create tokens at Settings > API Tokens with the smallest scope that works:

  • Email Sending API — for send.api.mailtrap.io and bulk.api.mailtrap.io. Scope per stream (transactional, bulk) when possible.
  • Email Testing API — for the Sandbox (sandbox.api.mailtrap.io). Always separate from live sending tokens.
  • Account-level API — for Contacts, Templates, Sending Domains, Suppressions, and other endpoints under https://mailtrap.io/api/accounts/{account_id}/....

A single token can cover several scopes if the user has the right plan; prefer narrower tokens (one stream / one project / one product surface) so a leak has limited blast radius. Reference: API tokens documentation.

Auth headers (two equivalent forms)

Mailtrap accepts either header. Use Bearer in examples — it's the more common HTTP convention and matches most generated SDK code.

FormHeaderWhen to use
Bearer (preferred)Authorization: Bearer $MAILTRAP_API_TOKENDefault for new code, SDKs, curl examples
Api-Token (legacy)Api-Token: $MAILTRAP_API_TOKENOlder clients or where Bearer is awkward

Do not send both at the same time. The same value goes in either header.

Where to put tokens

  • Local dev: environment variable, or .env file that is in .gitignore. Load with direnv, dotenv, or the framework's built-in mechanism.
  • CI / build: the CI provider's encrypted secret store (GitHub Actions secrets, GitLab CI variables, CircleCI contexts). Inject as env vars only.
  • Production / staging: a real secret manager (AWS Secrets Manager, GCP Secret Manager, Azure Key Vault, HashiCorp Vault, Doppler, 1Password, etc.). Rotate on a schedule.
  • Agent / LLM workflows: the host agent's secret store. Never paste a token into chat or a prompt.

Hard rules:

  • Never hardcode a token in source, config, or notebooks.
  • Never commit a token. If one lands in git, rotate it; history retention is forever.
  • Never pass a token on the command line as a flag — it leaks into shell history, ps, and CI logs.
  • Never let an LLM echo a literal token back into generated code. Use $VAR_NAME shell-var placeholders in all examples so generated code reaches for the env var, not the literal.
  • Never mix sandbox and live tokens. A leaked sandbox key must not be able to send real mail.

Recommended env var names

These names are used consistently across every other skill in this repo and across the example snippets below.

VariableUsed for
MAILTRAP_API_TOKENGeneral API: Email Send (transactional and bulk), Templates, Contacts, Sending Domains, Suppressions
MAILTRAP_SANDBOX_API_TOKENSandbox / Email Testing (separate scope)
MAILTRAP_ACCOUNT_IDPath parameter for account-scoped endpoints

If your environment uses different names, alias them once at startup so the examples in other skills work unchanged.

Resolving account_id automatically

account_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 owner
  • 100 — Admin
  • 10 — Viewer (read-only on most endpoints)

One-liner to cache as an env var (pick the right account if the token can see more than one):

export MAILTRAP_ACCOUNT_ID=$(curl -s https://mailtrap.io/api/accounts \
  -H "Authorization: Bearer $MAILTRAP_API_TOKEN" | jq '.[0].id')

Reference: Accounts API.

Quick reference

# 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 '{ ... }'

Common mistakes

MistakeFix
Hardcoding the token in code, config, or a notebookLoad 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 commitHistory keeps the value forever — rotate the token immediately, do not just remove the file
Pasting a token into chat / prompt / issueTreat chat as public; rotate if it happened
Using the live MAILTRAP_API_TOKEN against the sandbox hostSandbox uses its own scope and MAILTRAP_SANDBOX_API_TOKEN; mixing them either fails or sends real mail by accident
Hardcoding account_idResolve 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 severalFilter the GET /api/accounts response by name or access_levels (1000 = owner) instead of .[0]
Sending both Authorization and Api-Token headersPick one (Bearer for new code); duplicating them is unnecessary and confuses some intermediaries
Using a viewer-scoped token for writesCheck access_levels; writes need 100 (admin) or 1000 (owner) for the relevant account

GitHub Repository

mailtrap/mailtrap-skills
Pfad: skills/authorizing-api-requests
0
FAQ

Häufig gestellte Fragen

Was ist der Skill authorizing-api-requests?

authorizing-api-requests ist ein Claude Skill von mailtrap. Skills bündeln Anweisungen und Ressourcen, die Claude bei Bedarf lädt, um Aufgaben rund um authorizing-api-requests ohne zusätzliche Eingaben auszuführen.

Wie installiere ich authorizing-api-requests?

Verwende die Installationsbefehle auf dieser Seite: Füge authorizing-api-requests als Plugin zu Claude Code hinzu oder klone das Repository in dein Skills-Verzeichnis. Starte Claude danach neu, damit der Skill geladen wird.

Zu welcher Kategorie gehört authorizing-api-requests?

authorizing-api-requests gehört zur Kategorie Meta.

Kann ich authorizing-api-requests kostenlos nutzen?

Ja. authorizing-api-requests ist auf AIMCP gelistet und kann kostenlos installiert werden.

Verwandte Skills

content-collections
Meta

Diese Skill bietet eine produktionsgetestete Einrichtung für Content Collections – ein TypeScript-first-Tool, das Markdown/MDX-Dateien in typsichere Datensammlungen mit Zod-Validierung umwandelt. Verwenden Sie ihn beim Erstellen von Blogs, Dokumentationsseiten oder inhaltsstarken Vite + React-Anwendungen, um Typsicherheit und automatische Inhaltsvalidierung zu gewährleisten. Er behandelt alles von der Vite-Plugin-Konfiguration und MDX-Kompilierung bis hin zur Deployment-Optimierung und Schema-Validierung.

Skill ansehen
polymarket
Meta

Diese Fähigkeit ermöglicht es Entwicklern, Anwendungen mit der Polymarket-Prognosemärkte-Plattform zu erstellen, einschließlich API-Integration für Handel und Marktdaten. Sie bietet außerdem Echtzeit-Datenstreaming über WebSocket, um Live-Trades und Marktaktivitäten zu überwachen. Nutzen Sie sie zur Implementierung von Handelsstrategien oder zur Erstellung von Tools, die Live-Marktaktualisierungen verarbeiten.

Skill ansehen
creating-opencode-plugins
Meta

Diese Fähigkeit unterstützt Entwickler dabei, OpenCode-Plugins zu erstellen, die in über 25 Ereignistypen wie Befehle, Dateien und LSP-Operationen eingreifen. Sie bietet die Plugin-Struktur, Event-API-Spezifikationen und Implementierungsmuster für JavaScript/TypeScript-Module. Nutzen Sie sie, wenn Sie den Lebenszyklus des OpenCode KI-Assistenten mit benutzerdefinierter ereignisgesteuerter Logik abfangen, überwachen oder erweitern müssen.

Skill ansehen
sglang
Meta

SGLang ist ein hochperformantes LLM-Serving-Framework, das sich auf schnelle, strukturierte Generierung für JSON, Regex und agentenbasierte Workflows unter Verwendung seines RadixAttention-Prefix-Cachings spezialisiert. Es bietet deutlich schnellere Inferenz, insbesondere für Aufgaben mit wiederholten Präfixen, was es ideal für komplexe, strukturierte Ausgaben und Mehrfachdialoge macht. Wählen Sie SGLang gegenüber Alternativen wie vLLM, wenn Sie constrained decoding benötigen oder Anwendungen mit umfangreicher Präfix-Weitergabe entwickeln.

Skill ansehen