Skip to content

Ejemplos de código ​

Ejemplos mínimos para autenticación, listar documentos y crear un socio de negocio. Sustituya TU_KEY_ID, TU_SECRET y la URL base por sus valores reales.

cURL ​

Autenticación en cada petición ​

bash
export KEY_ID="abk_xxxx"
export SECRET="su_secret"
export BASE="https://api.abaco.hn"

curl -X GET "$BASE/documents?page=1&limit=5" \
  -H "Authorization: Bearer $KEY_ID:$SECRET"

Crear un socio de negocio ​

bash
curl -X POST "$BASE/business-partners" \
  -H "Authorization: Bearer $KEY_ID:$SECRET" \
  -H "Content-Type: application/json" \
  -d '{"name":"Cliente Ejemplo","partner_type":"C","rtn":"08011990123456","email":"cliente@ejemplo.com"}'

Crear una factura de venta (resumen) ​

JSON completo y campos de línea: Documentos → Crear.

bash
curl -X POST "$BASE/documents" \
  -H "Authorization: Bearer $KEY_ID:$SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "01",
    "businessPartnerId": 10,
    "date": "2026-11-03",
    "currency": "HNL",
    "subtotal": 1000.00,
    "discountAmount": 0,
    "taxAmount": 150.00,
    "total": 1150.00,
    "lines": [{
      "productId": 5,
      "code": "PROD-001",
      "description": "Producto ejemplo",
      "quantity": 2,
      "price": 500.00,
      "discount": 0,
      "taxRate": "15",
      "subtotal": 1000.00,
      "total": 1150.00,
      "warehouseId": 1
    }]
  }'

Node.js (fetch) ​

javascript
const BASE = 'https://api.abaco.hn';
const KEY_ID = 'abk_xxxx';
const SECRET = 'su_secret';
const token = `${KEY_ID}:${SECRET}`;

// Listar documentos
const res = await fetch(`${BASE}/documents?page=1&limit=10`, {
  headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) {
  if (res.status === 429) throw new Error('Rate limit; reintentar más tarde');
  if (res.status === 401) throw new Error('API key inválida');
  throw new Error(await res.text());
}
const data = await res.json();
console.log(data.documents);

Python (requests) ​

python
import os
import requests

BASE = os.environ.get("ABACO_API_BASE", "https://api.abaco.hn")
KEY_ID = os.environ.get("ABACO_KEY_ID", "abk_xxxx")
SECRET = os.environ.get("ABACO_SECRET", "su_secret")
token = f"{KEY_ID}:{SECRET}"

headers = {"Authorization": f"Bearer {token}"}

# Listar documentos
r = requests.get(f"{BASE}/documents", params={"page": 1, "limit": 10}, headers=headers)
if r.status_code == 429:
    raise Exception("Rate limit; esperar y reintentar")
if r.status_code == 401:
    raise Exception("API key inválida")
r.raise_for_status()
data = r.json()
print(data["documents"])

Manejo de errores 401 y 429 ​

  • 401: Verificar que Key ID y Secret sean correctos y que la llave no esté revocada o expirada. Ver Autenticación.
  • 429: Esperar unos segundos y reintentar con backoff (ej. 2 s, 4 s, 8 s). Ver Límites y cuotas.

Referencia de API · Autenticación

Documentación API abaco · Changelog