Skip to main content
POST
/
api
/
auth
/
initialize
Initialize System
curl --request POST \
  --url https://api.example.com/api/auth/initialize
{
  "message": "<string>",
  "user": {
    "user.id": 123,
    "user.name": "<string>",
    "user.email": "<string>",
    "user.role": "<string>"
  },
  "access_token": "<string>",
  "token_type": "<string>"
}
Initialize the system by creating the first super administrator user. This endpoint is used during the initial setup of the application.

Authentication

This endpoint is public and does not require authentication. However, it can only be called once when the system has no users.
This endpoint can only be executed when there are zero users in the system. Once the first user is created, this endpoint will return an error.

Request Body

name
string
required
Full name of the super administrator
  • Maximum 255 characters
email
string
required
Email address for the super administrator account
  • Must be a valid email format
  • Maximum 255 characters
  • Must be unique
password
string
required
Password for the super administrator account
  • Minimum 8 characters
  • Must contain letters
  • Must contain mixed case (uppercase and lowercase)
  • Must contain numbers

Response

message
string
Status message indicating initialization result
user
object
Created super administrator user information
user.id
integer
User’s unique identifier
user.name
string
User’s full name
user.email
string
User’s email address
user.role
string
User’s role display name (will be “Super Administrador”)
access_token
string
Bearer token for authenticating subsequent API requests
token_type
string
Token type (always “Bearer”)

Code Examples

curl -X POST https://api.example.com/api/auth/initialize \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Super Admin",
    "email": "[email protected]",
    "password": "SecurePass123"
  }'

Response Examples

Success Response

200 OK
{
  "message": "Sistema inicializado exitosamente",
  "user": {
    "id": 1,
    "name": "Super Admin",
    "email": "[email protected]",
    "role": "Super Administrador"
  },
  "access_token": "1|abcdefghijklmnopqrstuvwxyz1234567890",
  "token_type": "Bearer"
}

Error Responses

400 Bad Request - System Already Initialized
{
  "message": "Sistema ya inicializado",
  "status": "error"
}
422 Unprocessable Entity - Validation Error
{
  "message": "The email has already been taken. (and 1 more error)",
  "errors": {
    "email": [
      "The email has already been taken."
    ],
    "password": [
      "The password must be at least 8 characters.",
      "The password must contain at least one uppercase and one lowercase letter.",
      "The password must contain at least one number."
    ]
  }
}
500 Internal Server Error
{
  "message": "Error al inicializar sistema: Database connection failed",
  "status": "error"
}

Initialization Process

When you call this endpoint, the system automatically:
  1. Creates all roles and permissions in the database
  2. Creates the super administrator role
  3. Creates the first user with super administrator privileges
  4. Marks the user’s email as verified
  5. Sets the user as active
  6. Generates an API access token with full permissions

Password Requirements

The password must meet the following criteria:
  • Minimum length: 8 characters
  • Letters: Must contain at least one letter
  • Mixed case: Must contain both uppercase and lowercase letters
  • Numbers: Must contain at least one numeric digit
This is a one-time operation. After the first user is created, you must use the /api/auth/login endpoint to authenticate and the /api/v1/auth/create-user endpoint (as a super admin) to create additional users.

Using the Access Token

After successful initialization, use the returned access token in the Authorization header for all authenticated requests:
Authorization: Bearer 1|abcdefghijklmnopqrstuvwxyz1234567890

Next Steps

After initializing the system:
  1. Store the access token securely
  2. Configure your first company using the Companies API
  3. Set up branches and configure SUNAT credentials
  4. Create additional users as needed using the Create User endpoint

Build docs developers (and LLMs) love