API Authentication
Pelajari cara mengautentikasi dengan BotLaunch API menggunakan JWT token. Amankan request Anda dan kelola akses ke resource Anda.
Autentikasi stateless yang aman menggunakan JSON Web Tokens.
Access token kedaluwarsa dalam 1 jam, refresh token dalam 7 hari.
Gunakan refresh token untuk mendapatkan access token baru secara mulus.
Alur Autentikasi
Ikuti langkah-langkah ini untuk mengautentikasi dan membuat request API yang aman.
Login
Dapatkan token dengan kredensial
Simpan Token
Simpan kedua token dengan aman
Buat Request
Sertakan token di header
Refresh
Dapatkan token baru saat kedaluwarsa
Authentication Endpoints
/api/auth/loginAutentikasi pengguna dan terima access serta refresh token.
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/registerBuat akun pengguna dan organisasi baru.
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/refreshTukarkan refresh token dengan access token baru.
Example Request
curl -X POST "https://api.botlaunch.io/api/auth/refresh" \
-H "Content-Type: application/json" \
-d '{
"refreshToken": "your-refresh-token"
}'Rotasi Token
Setiap request refresh mengembalikan refresh token baru. Simpan dan gunakan refresh token terbaru untuk request berikutnya.
/api/auth/logoutBatalkan sesi saat ini dan cabut token.
Example Request
curl -X POST "https://api.botlaunch.io/api/auth/logout" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json"Menggunakan Access Token
Sertakan access token Anda di header Authorization untuk semua request 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"
}
});Header yang Diperlukan
AuthorizationBearer tokenx-organization-idOrganization IDContent-Typeapplication/jsonPraktik Keamanan Terbaik
- Simpan token dengan aman (jangan pernah di localStorage untuk web)
- Gunakan HTTPS untuk semua request API
- Implementasikan refresh token sebelum kedaluwarsa
- Cabut token saat logout atau peristiwa keamanan
Error Autentikasi
Error autentikasi umum dan cara menanganinya.
| 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 |