API autenticación

Aprende a autenticarte con la API de BotLaunch usando tokens JWT. Protege tus solicitudes y gestiona el acceso a tus recursos.

Personal API keys for AI (bl_live_)

To let an AI assistant (Claude, ChatGPT, Cursor) manage your bot and Mini App shop, create a personal API key in the dashboard (Settings → API & AI) and send it as Authorization: Bearer bl_live_…. Keys are scoped and rate-limited per plan, and can never reach billing or admin. The AI should call GET /context first to read your plan and permissions.

Prefer a native integration? Point any MCP-capable client (Cursor, Claude Code, or a custom MCP integration) at the live MCP server https://api.botlaunch.io/api/v1/mcp with the same key, and BotLaunch appears as a native tool set of 12 tools.

Prompts, templates and SDKs: github.com/BotLaunch/botlaunch-ai-companion

Tokens JWT

Autenticación segura sin estado utilizando JSON Web Tokens.

Expiración de tokens

Los tokens de acceso expiran en 1 hora, los tokens de actualización en 7 días.

Actualización automática

Usa tokens de actualización para obtener nuevos tokens de acceso de forma transparente.

Flujo de autenticación

Sigue estos pasos para autenticarte y realizar solicitudes seguras a la API.

1

Iniciar sesión

Obtener tokens con credenciales

2

Almacenar tokens

Almacenar ambos tokens de forma segura

3

Realizar solicitudes

Incluir token en los encabezados

4

Actualizar

Obtener nuevo token cuando expire

Endpoints de autenticación

POST/api/auth/login

Autenticar un usuario y recibir tokens de acceso y actualización.

Request body

FieldTypeRequiredDescription
emailstringUser's email address
passwordstringUser's password

Example request

curl -X POST "https://api.botlaunch.io/api/auth/login" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "your-secure-password"
  }'
bash

Example response

{
  "data": {
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "expiresIn": 3600,
    "user": {
      "id": "usr_abc123",
      "email": "user@example.com",
      "role": "CLIENT_OWNER"
    }
  },
  "message": "Login successful"
}
json
POST/api/auth/register

Crear una nueva cuenta de usuario y organización.

Request body

FieldTypeRequiredDescription
emailstringValid email address
passwordstringMin 8 chars, 1 uppercase, 1 number
namestringUser's full name
organizationNamestringOptionalOrganization name

Example request

curl -X POST "https://api.botlaunch.io/api/auth/register" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "newuser@example.com",
    "password": "SecureP@ssw0rd!",
    "name": "John Doe",
    "organizationName": "My Company"
  }'
bash
POST/api/auth/refresh

Intercambiar un token de actualización por un nuevo token de acceso.

Example request

curl -X POST "https://api.botlaunch.io/api/auth/refresh" \
  -H "Content-Type: application/json" \
  -d '{
    "refreshToken": "your-refresh-token"
  }'
bash

Rotación de tokens

Cada solicitud de actualización devuelve un nuevo token de actualización. Almacena y usa el último token de actualización para las solicitudes posteriores.

POST/api/auth/logout

Invalidar la sesión actual y revocar tokens.

Example request

curl -X POST "https://api.botlaunch.io/api/auth/logout" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"
bash

Uso de tokens de acceso

Incluye tu token de acceso en el encabezado Authorization para todas las solicitudes a la API.

// Include the access token in all API requests
const response = await fetch("https://api.botlaunch.io/api/bots", {
  headers: {
    "Authorization": "Bearer eyJhbGciOiJIUzI1NiIs...",
    "x-organization-id": "org_xyz789",
    "Content-Type": "application/json"
  }
});
javascript

Encabezados requeridos

AuthorizationBearer token
x-organization-idOrganization ID
Content-Typeapplication/json

Mejores prácticas de seguridad

  • Almacena los tokens de forma segura (nunca en localStorage para web)
  • Usa HTTPS para todas las solicitudes a la API
  • Implementa la actualización del token antes de que expire
  • Revoca los tokens al cerrar sesión o en eventos de seguridad

Errores de autenticación

Errores comunes de autenticación y cómo manejarlos.

StatusErrorDescriptionSolution
401UnauthorizedMissing or invalid tokenCheck Authorization header
401Token ExpiredAccess token has expiredUse refresh token to get new access token
403ForbiddenInsufficient permissionsCheck user role and organization access
429Too Many RequestsLogin rate limit exceededWait and retry after cooldown
400Invalid CredentialsWrong email or passwordVerify credentials and try again