Administrator Authentication API
Base URL: http://localhost:8000/api/v1
Prefix: /accounts/admins
Auth: JWT Bearer token for protected endpoints
Headers: Content-Type: application/json
1. Admin Login
Authenticate an admin user and return JWT tokens.
/accounts/admins/login/Auth: Not required
Request Body
{
"email": "admin@example.com",
"password": "StrongPass123"
}Success Example
{
"success": true,
"message": "Admin logged in successfully.",
"data": {
"admin": {
"id": 1,
"full_name": "Admin User",
"email": "admin@example.com",
"phone": null,
"roles": [
"admin"
],
"status": "active",
"is_active": true,
"is_staff": true,
"is_superuser": false
},
"tokens": {
"refresh": "jwt_refresh_token",
"access": "jwt_access_token"
}
}
}Notes
-
Only users with the
adminrole can log in through this endpoint. -
Inactive, blocked, deleted, customer, and seller accounts are rejected.
2. Admin Logout
Logout an admin session by blacklisting the refresh token.
/accounts/admins/logout/Auth: Required
Headers
Authorization: Bearer {{access_token}}Request Body
{
"refresh": "jwt_refresh_token"
}Success Example
{
"success": true,
"message": "Logged out successfully.",
"data": {}
}Notes
-
Requires an authenticated admin access token.
-
The submitted refresh token is blacklisted.
3. Refresh Admin JWT Access Token
Generate a new admin access token from a valid admin refresh token.
/accounts/admins/token/refresh/Auth: Not required
Request Body
{
"refresh": "jwt_refresh_token"
}Success Example
{
"success": true,
"message": "Access token refreshed successfully.",
"data": {
"access": "new_jwt_access_token"
}
}Notes
-
The refresh token must belong to an admin user.
-
Customer and seller refresh tokens are rejected.
4. Change Admin Password
Change the password for the currently authenticated admin.
/accounts/admins/change-password/Auth: Required
Headers
Authorization: Bearer {{access_token}}Request Body
{
"current_password": "StrongPass123",
"new_password": "NewStrongPass123"
}Success Example
{
"success": true,
"message": "Password changed successfully.",
"data": {}
}Notes
-
Requires an authenticated admin access token.
-
current_passwordmust match the admin's existing password. -
new_passwordmust pass Django password validation.
5. Send Admin Reset Password Email
Send password reset instructions to an admin email address.
/accounts/admins/send-reset-password-email/Auth: Not required
Request Body
{
"email": "admin@example.com"
}Success Example
{
"success": true,
"message": "If the email exists, password-reset instructions were sent.",
"data": {}
}Notes
-
The response is generic to avoid exposing whether an email exists.
-
Reset instructions are only sent when the email belongs to an admin user.
6. Reset Admin Password
Reset an admin password using a password reset token.
/accounts/admins/reset-password/Auth: Not required
Request Body
{
"token": "password_reset_token",
"password": "ResetStrongPass123"
}Success Example
{
"success": true,
"message": "Password reset successfully.",
"data": {}
}Notes
-
The token must be a valid, unexpired admin password reset token.
-
passwordmust pass Django password validation.
Common Success Format
{
"success": true,
"message": "Success message.",
"data": {}
}Common Error Format
{
"success": false,
"message": "Validation failed.",
"errors": {
"email": [
"Enter a valid email address."
]
}
}