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()Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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()Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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."
}
Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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."
}
Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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()Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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."
}
Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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()Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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"
}
Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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()Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
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()Received response:
Request failed with error:
Tip: Check that you're properly connected to the network.
If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
You can check the Dev Tools console for debugging information.
Response
Response Fields
deleted
Estado de la operación de eliminación