Skip to main content
POST
/
api
/
login
Login
curl --request POST \
  --url https://api.example.com/api/login \
  --header 'Content-Type: application/json' \
  --data '
{
  "usuario_login": "<string>",
  "usuario_password": "<string>"
}
'
{
  "token": "<string>",
  "user": {
    "usuario_id": 123,
    "usuario_login": "<string>",
    "usuario_correo": "<string>",
    "usuario_nombre": "<string>",
    "usuario_apellido": "<string>",
    "departamento_id": 123,
    "usuario_celular": "<string>",
    "access_id": 123,
    "profile": {}
  }
}

Endpoint

POST /api/login
Validates user credentials, logs the access attempt, and returns a JWT token upon successful authentication.

Authentication

No authentication required (public endpoint).

Request Body

usuario_login
string
required
Username for authentication
usuario_password
string
required
User password

Response

token
string
JWT token valid for 8 hours. Include this in the Authorization header for authenticated requests.
user
object
User profile data

Examples

curl -X POST https://api.ambiotec.com/api/login \
  -H "Content-Type: application/json" \
  -d '{
    "usuario_login": "johndoe",
    "usuario_password": "securePass123"
  }'

Success Response (200 OK)

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c3VhcmlvX2lkIjoxLCJ1c3VhcmlvX2xvZ2luIjoiam9obmRvZSIsInVzdWFyaW9fY29ycmVvIjoiam9obkBleGFtcGxlLmNvbSIsInVzdWFyaW9fbm9tYnJlIjoiSm9obiIsInVzdWFyaW9fYXBlbGxpZG8iOiJEb2UiLCJkZXBhcnRhbWVudG9faWQiOjUsInVzdWFyaW9fY2VsdWxhciI6IjEyMzQ1Njc4IiwiYWNjZXNzX2lkIjoxMjMsImlhdCI6MTY4OTI2MzYwMCwiZXhwIjoxNjg5MjkyNDAwfQ.xyz123abc456",
  "user": {
    "usuario_id": 1,
    "usuario_login": "johndoe",
    "usuario_correo": "[email protected]",
    "usuario_nombre": "John",
    "usuario_apellido": "Doe",
    "departamento_id": 5,
    "usuario_celular": "12345678",
    "access_id": 123,
    "profile": null
  }
}

Error Responses

400 Bad Request

Invalid or missing request parameters.
{
  "error": "Datos inválidos",
  "details": [
    {
      "field": "usuario_login",
      "message": "usuario_login is required"
    }
  ]
}

401 Unauthorized

Invalid credentials.
{
  "error": "Credenciales inválidas"
}

500 Internal Server Error

General server error.
{
  "error": "Error interno al iniciar sesión"
}

503 Service Unavailable

Database connection error.
{
  "error": "Servicio no disponible",
  "message": "No se puede conectar con la base de datos. Por favor, contacte a soporte del sistema."
}

Implementation Notes

  • Access attempts are logged in the database (both successful and failed)
  • Client metadata (IP address, platform, user agent) is captured from request headers
  • Failed login attempts are logged with is_successful: false
  • The access_id in the response links to the access log entry
  • Custom header x-client-info can be used to pass additional client data

Build docs developers (and LLMs) love