User API
This section describes the User-related API endpoints, which include user creation, retrieving user information, and updating user details.
1. Create User
Endpoint: api/v1/accounts/users/
Method: POST
Permissions: AllowAny
This endpoint is used to create a new user account. An OTP will be sent to the provided email for account verification.
Request Payload
{
"email": "user@example.com",
"password": "securepassword123",
"confirm_password": "securepassword123",
"first_name": "John",
"last_name": "Doe",
"phone": "+1234567890",
"gender": "M",
"country": "US"
}
Response Payload (Success)
{
"msg": "Email sent successfully!",
"data": {
"id": 1,
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"phone": "+1234567890",
"gender": "M",
"country": "US",
"created_at": "2024-12-03T12:00:00Z",
"updated_at": "2024-12-03T12:00:00Z"
}
}
Response Payload (Error)
{
"email": ["This field is required."]
}
2. Retrieve User Information
Endpoint: api/v1/accounts/users/<pk>/
Method: GET
Permissions: IsAuthenticated
This endpoint retrieves the authenticated user's details.
Request Payload No request body is required for this operation.
Response Payload
{
"id": 1,
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"phone": "+1234567890",
"photo": "http://localhost:8000/media/photos/photo.jpg",
"address": "123 Main Street, Some City, Some Country",
"gender": "M",
"country": "US",
"birthday": "1990-01-01",
"has_initial_profile": true,
"created_at": "2024-12-03T12:00:00Z",
"updated_at": "2024-12-03T12:00:00Z"
}
3. Update User Information
Endpoint: api/v1/accounts/users/<pk>/
Method: PATCH
Permissions: IsAuthenticated
This endpoint allows the authenticated user or an admin to update the user's profile information.
Request Payload
{
"email": "new-email@example.com",
"first_name": "John",
"last_name": "Doe",
"phone": "+1234567890",
"gender": "M",
"country": "US"
}
Response Payload (Success)
{
"id": 1,
"email": "new-email@example.com",
"first_name": "John",
"last_name": "Doe",
"phone": "+1234567890",
"gender": "M",
"country": "US",
"created_at": "2024-12-03T12:00:00Z",
"updated_at": "2024-12-03T12:00:00Z"
}
Response Payload (Error)
{
"error": "User not found"
}
Explanation:
- Request Payload: The request data for each API call is shown inside a code block, which is formatted as
json. It specifies the required data to be sent in the body of the request. - Response Payload: The expected response data, both on success and error, is also included in a code block.
- The sections are clearly separated for each method (
POST,GET,PATCH), making the documentation easy to read.