API Login Documentation

Login Request

To authenticate and receive a token, make a POST request to the following endpoint:

POST /api/login

Request Body:


{
    "user_name": "john_doe",
    "password": "password"
}
                

Successful Response (Status Code: 200):


{
    "status": "success",
    "code": 200,
    "message": "Login successful",
    "data": {
        "user": {
            "id": 2,
            "user_name": "john_doe",
            "first_name": "John",
            "last_name": "Doe",
            "email": "john@example.com",
            "mobile": "1234567890",
            "status": "1",
            "created_at": "2025-06-24T04:26:31.000000Z"
        },
        "token": "your_jwt_token_here"
    }
}
                

Error Response (Status Code: 401 - Unauthorized):


{
    "status": "error",
    "code": 401,
    "message": "Unauthorized",
    "data": null
}
                

Error Response (Status Code: 422 - Validation Error):


{
    "status": "error",
    "code": 422,
    "message": "Validation error",
    "data": [
        "The password field is required."
    ]
}
                

Notes:

  • The user_name and password fields are required in the request body.
  • In case of successful login, you will receive a JWT token that can be used for subsequent requests.
  • If login fails, you will receive an Unauthorized error with a 401 status code.
  • If validation errors occur (e.g., missing fields), a 422 error code is returned along with details of the missing fields.