MENU navbar-image

Introduction

API RESTful para gestión de usuarios y clientes. Incluye autenticación mediante tokens Bearer (Laravel Sanctum) y operaciones CRUD completas.

## Autenticación

Esta API utiliza **Bearer Token** para autenticación. Para obtener tu token:

1. Realiza una petición POST a `/api/login` con tus credenciales (email y password)
2. Recibirás un token de acceso válido por 1 hora
3. Incluye el token en el header `Authorization: Bearer {token}` en tus peticiones

## Formato de respuesta

Todas las respuestas están en formato JSON. Las respuestas exitosas incluyen los datos solicitados, mientras que los errores incluyen un mensaje descriptivo.

## Rate Limiting

La API está protegida contra abuso. Se aplican límites de tasa estándar de Laravel.

## Códigos de estado

- `200 OK` - Solicitud exitosa
- `201 Created` - Recurso creado exitosamente
- `401 Unauthorized` - Token inválido o ausente
- `403 Forbidden` - Sin permisos suficientes
- `404 Not Found` - Recurso no encontrado
- `422 Unprocessable Entity` - Error de validación
- `500 Internal Server Error` - Error del servidor

Authenticating requests

To authenticate requests, include an Authorization header with the value "Bearer {YOUR_TOKEN}".

All authenticated endpoints are marked with a requires authentication badge in the documentation below.

Puedes obtener tu token de autenticación realizando login en POST /api/login. El token tiene una validez de 1 hora y otorga permisos para crear, actualizar, eliminar y visualizar usuarios y clientes.

Usuario

Crear un nuevo usuario

Example request:
curl --request POST \
    "http://localhost/api/create-user" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"name\": \"Juan Pérez\",
    \"email\": \"juan.perez@example.com\",
    \"password\": \"password\"
}"
const url = new URL(
    "http://localhost/api/create-user"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "name": "Juan Pérez",
    "email": "juan.perez@example.com",
    "password": "password"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/create-user';
$response = $client->post(
    $url,
    [
        'headers' => [
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
        'json' => [
            'name' => 'Juan Pérez',
            'email' => 'juan.perez@example.com',
            'password' => 'password',
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/create-user'
payload = {
    "name": "Juan Pérez",
    "email": "juan.perez@example.com",
    "password": "password"
}
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('POST', url, headers=headers, json=payload)
response.json()

Request      

POST api/create-user

Headers

Content-Type        

Example: application/json

Accept        

Example: application/json

Body Parameters

name   string     

Nombre completo del usuario. El campo value no debe ser mayor que 255 caracteres. Example: Juan Pérez

email   string     

Correo electrónico del usuario. El campo value no es un correo válido. Example: juan.perez@example.com

password   string     

Contraseña del usuario. El campo debe contener al menos 6 caracteres. Example: password

Response

Response Fields

message        

Mensaje de estado de la operación

Inicio de sesión de usuario

Example request:
curl --request POST \
    "http://localhost/api/login" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"email\": \"gbailey@example.net\",
    \"password\": \"+-0pBNvYgxwmi\\/#iw\"
}"
const url = new URL(
    "http://localhost/api/login"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "email": "gbailey@example.net",
    "password": "+-0pBNvYgxwmi\/#iw"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/login';
$response = $client->post(
    $url,
    [
        'headers' => [
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
        'json' => [
            'email' => 'gbailey@example.net',
            'password' => '+-0pBNvYgxwmi/#iw',
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/login'
payload = {
    "email": "gbailey@example.net",
    "password": "+-0pBNvYgxwmi\/#iw"
}
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('POST', url, headers=headers, json=payload)
response.json()

Request      

POST api/login

Headers

Content-Type        

Example: application/json

Accept        

Example: application/json

Body Parameters

email   string     

Correo electrónico del usuario. El campo value no es un correo válido. Example: gbailey@example.net

password   string     

Contraseña del usuario. El campo debe contener al menos 6 caracteres. Example: +-0pBNvYgxwmi/#iw

Response

Response Fields

token        

Token de autenticación del usuario

Obtener Usuario autenticado

requires authentication

Example request:
curl --request GET \
    --get "http://localhost/api/user/get-user" \
    --header "Authorization: Bearer {YOUR_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/user/get-user"
);

const headers = {
    "Authorization": "Bearer {YOUR_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/user/get-user';
$response = $client->get(
    $url,
    [
        'headers' => [
            'Authorization' => 'Bearer {YOUR_TOKEN}',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/user/get-user'
headers = {
  'Authorization': 'Bearer {YOUR_TOKEN}',
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('GET', url, headers=headers)
response.json()

Example response (401):

Show headers
cache-control: no-cache, private
content-type: application/json
access-control-allow-origin: *
 

{
    "message": "Unauthenticated."
}
 

Request      

GET api/user/get-user

Headers

Authorization        

Example: Bearer {YOUR_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Response

Response Fields

user        

Información del usuario autenticado

Obtener todos los usuarios

requires authentication

Example request:
curl --request GET \
    --get "http://localhost/api/user/users/all" \
    --header "Authorization: Bearer {YOUR_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/user/users/all"
);

const headers = {
    "Authorization": "Bearer {YOUR_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/user/users/all';
$response = $client->get(
    $url,
    [
        'headers' => [
            'Authorization' => 'Bearer {YOUR_TOKEN}',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/user/users/all'
headers = {
  'Authorization': 'Bearer {YOUR_TOKEN}',
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('GET', url, headers=headers)
response.json()

Example response (401):

Show headers
cache-control: no-cache, private
content-type: application/json
access-control-allow-origin: *
 

{
    "message": "Unauthenticated."
}
 

Request      

GET api/user/users/all

Headers

Authorization        

Example: Bearer {YOUR_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Cerrar sesión de usuario

requires authentication

Example request:
curl --request POST \
    "http://localhost/api/user/logout" \
    --header "Authorization: Bearer {YOUR_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/user/logout"
);

const headers = {
    "Authorization": "Bearer {YOUR_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "POST",
    headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/user/logout';
$response = $client->post(
    $url,
    [
        'headers' => [
            'Authorization' => 'Bearer {YOUR_TOKEN}',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/user/logout'
headers = {
  'Authorization': 'Bearer {YOUR_TOKEN}',
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('POST', url, headers=headers)
response.json()

Request      

POST api/user/logout

Headers

Authorization        

Example: Bearer {YOUR_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Response

Response Fields

message        

Mensaje de estado de la operación

Cliente

Obtener todos los clientes

requires authentication

Example request:
curl --request GET \
    --get "http://localhost/api/customers" \
    --header "Authorization: Bearer {YOUR_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/customers"
);

const headers = {
    "Authorization": "Bearer {YOUR_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/customers';
$response = $client->get(
    $url,
    [
        'headers' => [
            'Authorization' => 'Bearer {YOUR_TOKEN}',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/customers'
headers = {
  'Authorization': 'Bearer {YOUR_TOKEN}',
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('GET', url, headers=headers)
response.json()

Example response (401):

Show headers
cache-control: no-cache, private
content-type: application/json
access-control-allow-origin: *
 

{
    "message": "Unauthenticated."
}
 

Request      

GET api/customers

Headers

Authorization        

Example: Bearer {YOUR_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Response

Response Fields

data        

Lista de clientes

Crear un nuevo cliente

requires authentication

Example request:
curl --request POST \
    "http://localhost/api/customers" \
    --header "Authorization: Bearer {YOUR_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"first_name\": \"Juan\",
    \"last_name\": \"Pérez\",
    \"email\": \"juan.perez@example.com\",
    \"phone\": \"987654321\",
    \"description\": \"Cliente VIP\",
    \"status\": false
}"
const url = new URL(
    "http://localhost/api/customers"
);

const headers = {
    "Authorization": "Bearer {YOUR_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "first_name": "Juan",
    "last_name": "Pérez",
    "email": "juan.perez@example.com",
    "phone": "987654321",
    "description": "Cliente VIP",
    "status": false
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/customers';
$response = $client->post(
    $url,
    [
        'headers' => [
            'Authorization' => 'Bearer {YOUR_TOKEN}',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
        'json' => [
            'first_name' => 'Juan',
            'last_name' => 'Pérez',
            'email' => 'juan.perez@example.com',
            'phone' => '987654321',
            'description' => 'Cliente VIP',
            'status' => false,
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/customers'
payload = {
    "first_name": "Juan",
    "last_name": "Pérez",
    "email": "juan.perez@example.com",
    "phone": "987654321",
    "description": "Cliente VIP",
    "status": false
}
headers = {
  'Authorization': 'Bearer {YOUR_TOKEN}',
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('POST', url, headers=headers, json=payload)
response.json()

Request      

POST api/customers

Headers

Authorization        

Example: Bearer {YOUR_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Body Parameters

first_name   string     

Nombre del cliente. El campo value no debe ser mayor que 100 caracteres. Example: Juan

last_name   string     

Apellido del cliente. El campo value no debe ser mayor que 100 caracteres. Example: Pérez

email   string     

Correo electrónico del cliente. El campo value no es un correo válido. Example: juan.perez@example.com

phone   string  optional    

Teléfono del cliente (9 caracteres). El campo value debe contener 9 caracteres. Example: 987654321

description   string  optional    

Descripción adicional del cliente. Example: Cliente VIP

status   boolean  optional    

Estado del cliente. Example: false

Response

Response Fields

data        

Información del cliente creado

Obtener un cliente específico

requires authentication

Example request:
curl --request GET \
    --get "http://localhost/api/customers/1" \
    --header "Authorization: Bearer {YOUR_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/customers/1"
);

const headers = {
    "Authorization": "Bearer {YOUR_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/customers/1';
$response = $client->get(
    $url,
    [
        'headers' => [
            'Authorization' => 'Bearer {YOUR_TOKEN}',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/customers/1'
headers = {
  'Authorization': 'Bearer {YOUR_TOKEN}',
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('GET', url, headers=headers)
response.json()

Example response (401):

Show headers
cache-control: no-cache, private
content-type: application/json
access-control-allow-origin: *
 

{
    "message": "Unauthenticated."
}
 

Example response (404):


{
    "message": "Cliente no encontrado"
}
 

Request      

GET api/customers/{id}

Headers

Authorization        

Example: Bearer {YOUR_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

URL Parameters

id   integer     

ID del cliente. Example: 1

Response

Response Fields

data        

Información del cliente

Actualizar un cliente existente

requires authentication

Example request:
curl --request PUT \
    "http://localhost/api/customers/1" \
    --header "Authorization: Bearer {YOUR_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"first_name\": \"Juan\",
    \"last_name\": \"Pérez\",
    \"email\": \"juan.perez@example.com\",
    \"phone\": \"987654321\",
    \"description\": \"Cliente VIP actualizado\",
    \"status\": false
}"
const url = new URL(
    "http://localhost/api/customers/1"
);

const headers = {
    "Authorization": "Bearer {YOUR_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "first_name": "Juan",
    "last_name": "Pérez",
    "email": "juan.perez@example.com",
    "phone": "987654321",
    "description": "Cliente VIP actualizado",
    "status": false
};

fetch(url, {
    method: "PUT",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/customers/1';
$response = $client->put(
    $url,
    [
        'headers' => [
            'Authorization' => 'Bearer {YOUR_TOKEN}',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
        'json' => [
            'first_name' => 'Juan',
            'last_name' => 'Pérez',
            'email' => 'juan.perez@example.com',
            'phone' => '987654321',
            'description' => 'Cliente VIP actualizado',
            'status' => false,
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/customers/1'
payload = {
    "first_name": "Juan",
    "last_name": "Pérez",
    "email": "juan.perez@example.com",
    "phone": "987654321",
    "description": "Cliente VIP actualizado",
    "status": false
}
headers = {
  'Authorization': 'Bearer {YOUR_TOKEN}',
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('PUT', url, headers=headers, json=payload)
response.json()

Request      

PUT api/customers/{id}

PATCH api/customers/{id}

Headers

Authorization        

Example: Bearer {YOUR_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

URL Parameters

id   integer     

ID del cliente a actualizar. Example: 1

Body Parameters

first_name   string  optional    

Nombre del cliente. El campo value no debe ser mayor que 100 caracteres. Example: Juan

last_name   string  optional    

Apellido del cliente. El campo value no debe ser mayor que 100 caracteres. Example: Pérez

email   string  optional    

Correo electrónico del cliente. El campo value no es un correo válido. Example: juan.perez@example.com

phone   string  optional    

Teléfono del cliente (9 caracteres). El campo value debe contener 9 caracteres. Example: 987654321

description   string  optional    

Descripción adicional del cliente. Example: Cliente VIP actualizado

status   boolean  optional    

Estado del cliente. Example: false

Response

Response Fields

data        

Información del cliente actualizado

Eliminar un cliente

requires authentication

Example request:
curl --request DELETE \
    "http://localhost/api/customers/1" \
    --header "Authorization: Bearer {YOUR_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/customers/1"
);

const headers = {
    "Authorization": "Bearer {YOUR_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "DELETE",
    headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$url = 'http://localhost/api/customers/1';
$response = $client->delete(
    $url,
    [
        'headers' => [
            'Authorization' => 'Bearer {YOUR_TOKEN}',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
    ]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json

url = 'http://localhost/api/customers/1'
headers = {
  'Authorization': 'Bearer {YOUR_TOKEN}',
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request('DELETE', url, headers=headers)
response.json()

Request      

DELETE api/customers/{id}

Headers

Authorization        

Example: Bearer {YOUR_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

URL Parameters

id   integer     

ID del cliente a eliminar. Example: 1

Response

Response Fields

deleted        

Estado de la operación de eliminación