API-Dokumentation

OTP API

API zum Versenden und Verifizieren von E-Mail-Authentifizierungscodes.

Erforderliche Berechtigung: otp

POST /api/v1/otp/send

Sendet einen Authentifizierungscode per E-Mail.

Request Body

{
  "email": "user@example.com",
  "template": "login",           // optional: login, signup, reset
  "expires_in": 300,             // optional: seconds (default: 300)
  "code_length": 6               // optional: 4-8 (default: 6)
}

Response

{
  "success": true,
  "data": {
    "session_id": "abc123...",
    "email": "user@example.com",
    "expires_at": "2026-01-10T12:05:00Z"
  }
}
POST /api/v1/otp/verify

Verifiziert einen Authentifizierungscode.

Request Body

{
  "session_id": "abc123...",
  "code": "123456"
}

Response (Success)

{
  "success": true,
  "data": {
    "verified": true,
    "email": "user@example.com"
  }
}

Response (Failed)

{
  "success": false,
  "error": {
    "code": "INVALID_CODE",
    "message": "The verification code is invalid or expired."
  }
}
POST /api/v1/otp/resend

Sendet den Authentifizierungscode erneut.

Request Body

{
  "session_id": "abc123..."
}

Response

{
  "success": true,
  "data": {
    "session_id": "abc123...",
    "expires_at": "2026-01-10T12:05:00Z"
  }
}
GET /api/v1/otp/status/{session_id}

Prüft den Status einer OTP-Sitzung.

Response

{
  "success": true,
  "data": {
    "session_id": "abc123...",
    "email": "user@example.com",
    "status": "pending",          // pending, verified, expired
    "attempts": 2,
    "max_attempts": 5,
    "expires_at": "2026-01-10T12:05:00Z"
  }
}

Beispiele

cURL

# 1. Send OTP
curl -X POST https://dev.mailpass.im/api/v1/otp/send \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com"}'

# 2. Verify OTP
curl -X POST https://dev.mailpass.im/api/v1/otp/verify \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"session_id": "abc123...", "code": "123456"}'

JavaScript (fetch)

// Send OTP
const response = await fetch('https://dev.mailpass.im/api/v1/otp/send', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ email: 'user@example.com' })
});
const data = await response.json();

Wir verwenden Cookies

Wir verwenden Cookies zur Verbesserung Ihres Erlebnisses. Sie können auswählen, welche Cookie-Kategorien Sie erlauben. Erfahren Sie mehr