Skip to main content
POST
/
api
/
register
Register
curl --request POST \
  --url https://api.example.com/api/register \
  --header 'Content-Type: application/json' \
  --data '
{
  "usuarioLogin": "<string>",
  "usuarioCorreo": "<string>",
  "usuarioPassword": "<string>",
  "usuarioNombre": "<string>",
  "usuarioApellido": "<string>",
  "departamentoId": 123,
  "usuarioFechaNacimiento": "<string>",
  "usuarioCelular": "<string>",
  "usuarioDpi": "<string>",
  "usuarioTipoDocumento": 123,
  "usuarioNit": "<string>",
  "usuarioRolId": 123,
  "poseeLicencia": true,
  "licenciaTipo": 123,
  "licenciaNumero": "<string>",
  "licenciaPrimerAnio": 123,
  "licenciaFechaVencimiento": "<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>",
    "profile": {}
  }
}

Endpoint

POST /api/register
Creates a new user account with optional license information and returns a JWT token for immediate authentication.

Authentication

No authentication required (public endpoint).

Request Body

Required Fields

usuarioLogin
string
required
Unique username for the account. Must not already exist in the system.
usuarioCorreo
string
required
Valid email address. Must be unique and follow email format.
usuarioPassword
string
required
User password. Minimum length: 6 characters.
usuarioNombre
string
required
User’s first name.
usuarioApellido
string
required
User’s last name.
departamentoId
integer
required
Department ID the user belongs to. Must be a valid department ID from the catalog.

Optional Fields

usuarioFechaNacimiento
string
User’s date of birth in ISO 8601 format (e.g., 2000-01-15T00:00:00Z).
usuarioCelular
string
User’s mobile phone number.
usuarioDpi
string
User’s identification document number.
usuarioTipoDocumento
integer
Document type ID.
usuarioNit
string
User’s tax identification number (NIT).
usuarioRolId
integer
Role ID to assign to the user. Must be a valid integer >= 0.

License Fields

poseeLicencia
boolean
Indicates if the user has a license. If true, license fields become required.
licenciaTipo
integer
License type ID. Required if poseeLicencia is true.
licenciaNumero
string
License number. Required if poseeLicencia is true.
licenciaPrimerAnio
integer
Year the license was first issued.
licenciaFechaVencimiento
string
License expiration date in ISO 8601 format (e.g., 2025-12-31).

Response

token
string
JWT token valid for 8 hours. Use this token in the Authorization header for authenticated requests.
user
object
Created user’s public profile data

Examples

curl -X POST https://api.ambiotec.com/api/register \
  -H "Content-Type: application/json" \
  -d '{
    "usuarioLogin": "johndoe",
    "usuarioCorreo": "[email protected]",
    "usuarioPassword": "securePass123",
    "usuarioNombre": "John",
    "usuarioApellido": "Doe",
    "departamentoId": 5,
    "usuarioCelular": "12345678"
  }'

Success Response (201 Created)

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

Error Responses

400 Bad Request

Invalid or missing required parameters.
{
  "error": "Datos inválidos",
  "details": [
    {
      "field": "usuarioCorreo",
      "message": "Invalid email format"
    },
    {
      "field": "usuarioPassword",
      "message": "Password must be at least 6 characters"
    }
  ]
}
Invalid license type when license is specified.
{
  "error": "Tipo de licencia invalido"
}
Missing license number when license is specified.
{
  "error": "El numero de licencia es obligatorio"
}

409 Conflict

Username or email already exists.
{
  "error": "Login o correo ya registrado"
}

500 Internal Server Error

General server error during registration.
{
  "error": "Error interno al registrar usuario"
}

Implementation Notes

  • Passwords are securely hashed before storage (handled by database function fn_register_user)
  • If license information is provided, the license reminder scheduler is automatically refreshed
  • All license fields are validated as a group - if poseeLicencia is true, license type and number are required
  • The endpoint returns a JWT token immediately, allowing users to authenticate without a separate login
  • Database function handles duplicate checking and raises P0001 exception for conflicts
  • Unique constraint violations (code 23505) are also handled as conflicts

Validation Rules

FieldRule
usuarioLoginRequired, non-empty string
usuarioCorreoRequired, valid email format
usuarioPasswordRequired, minimum 6 characters
usuarioNombreRequired, non-empty string
usuarioApellidoRequired, non-empty string
departamentoIdRequired, valid integer
licenciaTipoRequired if poseeLicencia is true, must be positive integer
licenciaNumeroRequired if poseeLicencia is true, non-empty string

Build docs developers (and LLMs) love