Crear Organización
Registra una nueva organización en Lummy para comenzar a emitir facturas.
Endpoint
POST https://api.lummy.io/v1/organizations
| Entorno | URL |
|---|---|
| Producción | https://api.lummy.io/v1/organizations |
| Sandbox | https://sandbox.lummy.io/v1/organizations |
Headers
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...""01936ff8-9c6a-7b2e-8000-123456789abc"Body Parameters
"Mi Empresa S.A. de C.V.""Mi Empresa Sociedad Anónima de Capital Variable""XAXX010101000""601""12345"Ejemplos de Código
- cURL
- Node.js (TypeScript)
- Python
- PHP (Guzzle)
curl -X POST https://sandbox.lummy.io/organizations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "x-idempotency: $(uuidgen)" \
-d '{
"name": "Mi Empresa S.A. de C.V.",
"legalName": "Mi Empresa S.A. de C.V.",
"rfc": "XAXX010101000",
"taxRegime": "601",
"zipCode": "12345"
}'
Define ACCESS_TOKEN en tu shell:
export ACCESS_TOKEN="your-access-token"
El ACCESS_TOKEN se obtiene después de que el usuario se autentica en la plataforma Lummy.
import axios, { AxiosError } from 'axios';
import { v4 as uuidv4 } from 'uuid';
interface CreateOrganizationPayload {
name: string;
legalName?: string;
rfc: string;
taxRegime: string;
zipCode: string;
}
interface OrganizationResponse {
id: string;
name: string;
rfc: string;
isActive: boolean;
createdAt: string;
}
async function crearOrganizacion(): Promise<OrganizationResponse> {
const API_URL = 'https://sandbox.lummy.io/organizations';
const ACCESS_TOKEN = process.env.ACCESS_TOKEN!;
const payload: CreateOrganizationPayload = {
name: "Mi Empresa S.A. de C.V.",
legalName: "Mi Empresa S.A. de C.V.",
rfc: "XAXX010101000",
taxRegime: "601", // General de Ley Personas Morales
zipCode: "12345"
};
try {
const response = await axios.post<OrganizationResponse>(API_URL, payload, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${ACCESS_TOKEN}`,
'x-idempotency': uuidv4(),
},
});
console.log('Organizacion creada exitosamente');
console.log('ID:', response.data.id);
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
console.error('Error al crear organizacion:', axiosError.response?.data);
throw axiosError;
}
throw error;
}
}
// Ejecutar
crearOrganizacion();
npm install axios uuid
npm install -D @types/uuid
Define ACCESS_TOKEN en tu shell. El ACCESS_TOKEN se obtiene después de que el usuario se autentica en la plataforma Lummy.
import os
import requests
from uuid import uuid4
def crear_organizacion():
"""
Crea una nueva organización en Lummy.
"""
api_url = "https://sandbox.lummy.io/organizations"
access_token = os.getenv("ACCESS_TOKEN")
if not access_token:
raise ValueError("Debes definir ACCESS_TOKEN")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}",
"x-idempotency": str(uuid4()),
}
payload = {
"name": "Mi Empresa S.A. de C.V.",
"legalName": "Mi Empresa S.A. de C.V.",
"rfc": "XAXX010101000",
"taxRegime": "601", # General de Ley Personas Morales
"zipCode": "12345"
}
try:
response = requests.post(api_url, json=payload, headers=headers, timeout=30)
response.raise_for_status()
data = response.json()
print("Organizacion creada exitosamente")
print(f"ID: {data['id']}")
return data
except requests.exceptions.RequestException as e:
print(f"Error al crear organizacion: {e}")
if e.response:
print(f"Detalle: {e.response.text}")
raise
if __name__ == "__main__":
crear_organizacion()
pip install requests
Define ACCESS_TOKEN en tu shell. El ACCESS_TOKEN se obtiene después de que el usuario se autentica en la plataforma Lummy.
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Ramsey\Uuid\Uuid;
function crearOrganizacion()
{
$apiUrl = 'https://sandbox.lummy.io/organizations';
$accessToken = getenv('ACCESS_TOKEN');
if (!$accessToken) {
throw new Exception('Debes definir ACCESS_TOKEN');
}
$client = new Client([
'timeout' => 30,
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $accessToken,
'x-idempotency' => Uuid::uuid4()->toString(),
],
]);
$payload = [
"name" => "Mi Empresa S.A. de C.V.",
"legalName" => "Mi Empresa S.A. de C.V.",
"rfc" => "XAXX010101000",
"taxRegime" => "601",
"zipCode" => "12345"
];
try {
$response = $client->post($apiUrl, ['json' => $payload]);
$data = json_decode($response->getBody(), true);
echo "Organizacion creada exitosamente\n";
echo "ID: " . $data['id'] . "\n";
return $data;
} catch (RequestException $e) {
echo "Error al crear organizacion: " . $e->getMessage() . "\n";
if ($e->getResponse()) {
echo "Detalle: " . $e->getResponse()->getBody() . "\n";
}
throw $e;
}
}
// Ejecutar
try {
crearOrganizacion();
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}
composer require guzzlehttp/guzzle ramsey/uuid
Define ACCESS_TOKEN en tu shell. El ACCESS_TOKEN se obtiene después de que el usuario se autentica en la plataforma Lummy.
Respuestas
Todas las respuestas siguen el formato estándar StandardResponse.
201 Created
Organización creada exitosamente.
{
"requestId": "abc123-def456",
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Mi Empresa S.A. de C.V.",
"legalName": "Mi Empresa S.A. de C.V.",
"rfc": "XAXX010101000",
"taxRegime": "601",
"zipCode": "12345",
"isActive": true,
"createdAt": "2025-01-15T10:30:00.000Z"
},
"timestamp": "2025-01-15T10:30:00.000Z",
"path": "/organizations",
"method": "POST"
}
409 Conflict
Ya existe una organización con el mismo RFC.
{
"requestId": "abc123-def456",
"error": {
"message": "Ya existe una organización con el RFC: XAXX010101000",
"code": "ConflictException",
"status": 409
},
"timestamp": "2025-01-15T10:30:00.000Z",
"path": "/organizations",
"method": "POST"
}
400 Bad Request
Datos inválidos (RFC mal formado, CP incorrecto, etc).
{
"requestId": "abc123-def456",
"error": {
"message": "RFC inválido: debe tener 12 o 13 caracteres",
"code": "ValidationError",
"status": 400
},
"timestamp": "2025-01-15T10:30:00.000Z",
"path": "/organizations",
"method": "POST"
}