Obtener Sucursal por ID
Obtén los detalles completos de una sucursal específica.
Endpoint
GET https://api.lummy.io/v1/branches/{id}
| Entorno | URL |
|---|---|
| Producción | https://api.lummy.io/v1/branches/{id} |
| Sandbox | https://sandbox.lummy.io/v1/branches/{id} |
Path Parameters
{
"id": stringrequerido
↳Identificador único de la sucursal. Debe ser un UUID válido de una sucursal que pertenezca a la organización especificada en el header.
↳Formato: uuid
}
Headers
{
"Authorization": string,requerido
↳Token de autenticación en formato Bearer. Se obtiene del endpoint de autenticación y debe incluirse en todas las peticiones para verificar la identidad del usuario.
"x-organization-id": stringrequerido
↳Identificador único de la organización. Debe ser un UUID válido de una organización a la que el usuario autenticado tenga acceso.
↳Formato: uuid
}
Ejemplos de Código
- cURL
- Node.js (TypeScript)
- Python
- PHP (Guzzle)
curl -X GET "https://sandbox.lummy.io/branches/550e8400-e29b-41d4-a716-446655440001" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "x-organization-id: ${LUMMY_ORG_ID}"
import axios from 'axios';
interface Branch {
id: string;
name: string;
zipCode: string;
isMain: boolean;
isActive: boolean;
createdAt: string;
updatedAt: string;
}
async function obtenerSucursal(
organizationId: string,
branchId: string
): Promise<Branch> {
const API_URL = `https://sandbox.lummy.io/branches/${branchId}`;
const ACCESS_TOKEN = process.env.ACCESS_TOKEN!;
try {
const response = await axios.get<Branch>(API_URL, {
headers: {
'Authorization': `Bearer ${ACCESS_TOKEN}`,
'x-organization-id': organizationId,
},
});
console.log('Sucursal obtenida:');
console.log(`Nombre: ${response.data.name}`);
console.log(`CP: ${response.data.zipCode}`);
console.log(`Principal: ${response.data.isMain ? 'Sí' : 'No'}`);
console.log(`Activo: ${response.data.isActive ? 'Sí' : 'No'}`);
return response.data;
} catch (error) {
console.error('Error al obtener sucursal:', error);
throw error;
}
}
// Ejecutar
obtenerSucursal(
'550e8400-e29b-41d4-a716-446655440000',
'550e8400-e29b-41d4-a716-446655440001'
);
Dependencias
npm install axios
import os
import requests
def obtener_sucursal(organization_id: str, branch_id: str):
api_url = f"https://sandbox.lummy.io/branches/{branch_id}"
access_token = os.getenv("ACCESS_TOKEN")
if not access_token:
raise ValueError("Debes definir ACCESS_TOKEN")
headers = {
"Authorization": f"Bearer {access_token}",
"x-organization-id": organization_id
}
try:
response = requests.get(api_url, headers=headers, timeout=30)
response.raise_for_status()
branch = response.json()
print("Sucursal obtenida:")
print(f"Nombre: {branch['name']}")
print(f"CP: {branch['zipCode']}")
print(f"Principal: {'Sí' if branch['isMain'] else 'No'}")
print(f"Activo: {'Sí' if branch['isActive'] else 'No'}")
return branch
except requests.exceptions.RequestException as e:
print(f"Error al obtener sucursal: {e}")
if e.response:
print(f"Detalle: {e.response.text}")
raise
if __name__ == "__main__":
obtener_sucursal(
'550e8400-e29b-41d4-a716-446655440000',
'550e8400-e29b-41d4-a716-446655440001'
)
Dependencias
pip install requests
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
function obtenerSucursal(string $organizationId, string $branchId)
{
$apiUrl = "https://sandbox.lummy.io/branches/{$branchId}";
$accessToken = getenv('ACCESS_TOKEN');
if (!$accessToken) {
throw new Exception('Debes definir ACCESS_TOKEN');
}
$client = new Client(['timeout' => 30]);
try {
$response = $client->get($apiUrl, [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'x-organization-id' => $organizationId
]
]);
$branch = json_decode($response->getBody(), true);
echo "Sucursal obtenida:\n";
echo "Nombre: {$branch['name']}\n";
echo "CP: {$branch['zipCode']}\n";
echo "Principal: " . ($branch['isMain'] ? 'Sí' : 'No') . "\n";
echo "Activo: " . ($branch['isActive'] ? 'Sí' : 'No') . "\n";
return $branch;
} catch (RequestException $e) {
echo "Error al obtener sucursal: " . $e->getMessage() . "\n";
if ($e->getResponse()) {
echo "Detalle: " . $e->getResponse()->getBody() . "\n";
}
throw $e;
}
}
try {
obtenerSucursal(
'550e8400-e29b-41d4-a716-446655440000',
'550e8400-e29b-41d4-a716-446655440001'
);
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}
Dependencias
composer require guzzlehttp/guzzle
Respuestas
Todas las respuestas siguen el formato estándar StandardResponse.
200 OK
Sucursal obtenida exitosamente.
{
"type": ,opcional
"properties": opcional
}
{
"requestId": "abc123-def456",
"data": {
"id": "550e8400-e29b-41d4-a716-446655440001",
"name": "Matriz",
"zipCode": "64000",
"isMain": true,
"isActive": true,
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z"
},
"timestamp": "2025-01-15T10:30:00.000Z",
"path": "/branches/550e8400-e29b-41d4-a716-446655440001",
"method": "GET"
}
404 Not Found
La sucursal con el ID especificado no existe.
{
"requestId": "abc123-def456",
"error": {
"message": "Branch not found",
"code": "NotFoundException",
"status": 404
},
"timestamp": "2025-01-15T10:30:00.000Z",
"path": "/branches/550e8400-e29b-41d4-a716-446655440001",
"method": "GET"
}
400 Bad Request
Falta el header x-organization-id.
{
"requestId": "abc123-def456",
"error": {
"message": "Header requerido: x-organization-id. El contexto organizacional es obligatorio.",
"code": "ValidationError",
"status": 400
},
"timestamp": "2025-01-15T10:30:00.000Z",
"path": "/branches/550e8400-e29b-41d4-a716-446655440001",
"method": "GET"
}
401 Unauthorized
Token inválido o expirado.
{
"requestId": "abc123-def456",
"error": {
"message": "Unauthorized",
"code": "UnauthorizedException",
"status": 401
},
"timestamp": "2025-01-15T10:30:00.000Z",
"path": "/branches/550e8400-e29b-41d4-a716-446655440001",
"method": "GET"
}
403 Forbidden
No tienes acceso a la organización especificada.
{
"requestId": "abc123-def456",
"error": {
"message": "Usuario no autorizado para la organización: 550e8400-e29b-41d4-a716-446655440000.",
"code": "ForbiddenException",
"status": 403
},
"timestamp": "2025-01-15T10:30:00.000Z",
"path": "/branches/550e8400-e29b-41d4-a716-446655440001",
"method": "GET"
}