API احراز هویت
نحوه احراز هویت با API BotLaunch با استفاده از توکنهای JWT را بیاموزید. درخواستهای خود را ایمن کنید و دسترسی به منابع خود را مدیریت کنید.
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
احراز هویت بدون حالت و امن با استفاده از JSON Web Tokens.
توکنهای دسترسی در ۱ ساعت و توکنهای تازهسازی در ۷ روز منقضی میشوند.
از توکنهای تازهسازی برای دریافت توکنهای دسترسی جدید به صورت یکپارچه استفاده کنید.
جریان احراز هویت
این مراحل را برای احراز هویت و ارسال درخواستهای امن API دنبال کنید.
ورود
دریافت توکنها با اعتبارنامهها
ذخیره توکنها
ذخیره امن هر دو توکن
ارسال درخواستها
درج توکن در هدرها
تازهسازی
دریافت توکن جدید پس از انقضا
نقاط پایانی احراز هویت
/api/auth/loginاحراز هویت کاربر و دریافت توکنهای دسترسی و تازهسازی.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
| string | User's email address | ||
| password | string | User'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"
}'Example response
{
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 3600,
"user": {
"id": "usr_abc123",
"email": "user@example.com",
"role": "CLIENT_OWNER"
}
},
"message": "Login successful"
}/api/auth/registerایجاد حساب کاربری و سازمان جدید.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
| string | Valid email address | ||
| password | string | Min 8 chars, 1 uppercase, 1 number | |
| name | string | User's full name | |
| organizationName | string | Optional | Organization 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"
}'/api/auth/refreshتبدیل توکن تازهسازی به توکن دسترسی جدید.
Example request
curl -X POST "https://api.botlaunch.io/api/auth/refresh" \
-H "Content-Type: application/json" \
-d '{
"refreshToken": "your-refresh-token"
}'چرخش توکن
هر درخواست تازهسازی یک توکن تازهسازی جدید برمیگرداند. آخرین توکن تازهسازی را ذخیره کرده و برای درخواستهای بعدی استفاده کنید.
/api/auth/logoutباطل کردن نشست فعلی و لغو توکنها.
Example request
curl -X POST "https://api.botlaunch.io/api/auth/logout" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json"استفاده از توکنهای دسترسی
توکن دسترسی خود را در هدر Authorization برای تمام درخواستهای 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"
}
});هدرهای الزامی
AuthorizationBearer tokenx-organization-idOrganization IDContent-Typeapplication/jsonبهترین شیوههای امنیتی
- توکنها را به صورت امن ذخیره کنید (هرگز در localStorage برای وب)
- از HTTPS برای تمام درخواستهای API استفاده کنید
- تازهسازی توکن را قبل از انقضا پیادهسازی کنید
- توکنها را هنگام خروج یا رویدادهای امنیتی باطل کنید
خطاهای احراز هویت
خطاهای رایج احراز هویت و نحوه رسیدگی به آنها.
| Status | Error | Description | Solution |
|---|---|---|---|
| 401 | Unauthorized | Missing or invalid token | Check Authorization header |
| 401 | Token Expired | Access token has expired | Use refresh token to get new access token |
| 403 | Forbidden | Insufficient permissions | Check user role and organization access |
| 429 | Too Many Requests | Login rate limit exceeded | Wait and retry after cooldown |
| 400 | Invalid Credentials | Wrong email or password | Verify credentials and try again |