Inicio rápido
Crea una API key, haz tu primera petición y lleva una factura de borrador a emitida y cobrada en diez minutos.
Les guies per a desenvolupadors només estan disponibles en castellà i en anglès; aquesta es mostra en castellà. Llegeix-la en anglès →
En esta guía vas a crear un cliente, preparar una factura en borrador, emitirla, descargar su PDF y registrar el cobro. Cada paso tiene ejemplos en cURL, JavaScript (Node.js 18+ con fetch), Python (requests) y PHP (cURL).
Usa una organización de pruebas
Emitir una factura es irreversible y, si la organización tiene VeriFactu activo, se remite a la AEAT. Mientras desarrollas, trabaja en una organización de pruebas sin VeriFactu. Ver Entornos.
1. Crea una API key
- Entra en Billora con un usuario propietario o administrador y ve a Ajustes → API.
- Pulsa Crear API key, ponle un nombre que identifique la integración (por ejemplo, «ERP producción») y marca estos scopes:
contacts:write,invoices:write,payments:write,series:readytaxes:read. - Copia la clave. Empieza por
blr_y solo se muestra una vez: Billora guarda únicamente un hash.
Guárdala como variable de entorno; todos los ejemplos la leen de ahí:
export BILLORA_API_KEY="blr_…"2. Haz tu primera petición
Lista las series de numeración de la organización. Te servirá para comprobar que la clave funciona y para saber qué serie usar al facturar.
curl https://api.billora.app/api/v1/settings/series/ \
-H "Authorization: Bearer $BILLORA_API_KEY"// billora.mjs — helper reutilizado en el resto de pasos
const API = "https://api.billora.app/api/v1";
export async function billora(method, path, body, extraHeaders = {}) {
const res = await fetch(`${API}${path}`, {
method,
headers: {
Authorization: `Bearer ${process.env.BILLORA_API_KEY}`,
"Content-Type": "application/json",
...extraHeaders,
},
body: body ? JSON.stringify(body) : undefined,
});
const data = res.status === 204 ? null : await res.json();
if (!res.ok) throw new Error(`${data.code}: ${data.detail} (${data.request_id})`);
return data;
}
const series = await billora("GET", "/settings/series/");
console.log(series.results.filter((s) => s.type === "INVOICE"));# billora.py — sesión reutilizada en el resto de pasos
import os
import requests
API = "https://api.billora.app/api/v1"
session = requests.Session()
session.headers.update({"Authorization": f"Bearer {os.environ['BILLORA_API_KEY']}"})
def billora(method, path, json=None, headers=None):
res = session.request(method, f"{API}{path}", json=json, headers=headers, timeout=30)
data = None if res.status_code == 204 else res.json()
if not res.ok:
raise RuntimeError(f"{data['code']}: {data['detail']} ({data['request_id']})")
return data
series = billora("GET", "/settings/series/")
print([s for s in series["results"] if s["type"] == "INVOICE"])<?php
// billora.php — función reutilizada en el resto de pasos
function billora(string $method, string $path, ?array $body = null, array $headers = []): ?array {
$ch = curl_init("https://api.billora.app/api/v1" . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array_merge([
"Authorization: Bearer " . getenv("BILLORA_API_KEY"),
"Content-Type: application/json",
], $headers),
CURLOPT_POSTFIELDS => $body !== null ? json_encode($body) : null,
]);
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = $status === 204 ? null : json_decode($raw, true);
if ($status >= 400) {
throw new RuntimeException("{$data['code']}: {$data['detail']} ({$data['request_id']})");
}
return $data;
}
$series = billora("GET", "/settings/series/");
print_r(array_filter($series["results"], fn ($s) => $s["type"] === "INVOICE"));La respuesta es una lista paginada. Apunta el id de la serie de facturas ("type": "INVOICE"):
{
"count": 3,
"next": null,
"previous": null,
"results": [
{ "id": 12, "type": "INVOICE", "code": "F", "name": "Facturas", "prefix": "F-", "next_number": 1 },
{ "id": 13, "type": "CREDIT_NOTE", "code": "R", "name": "Rectificativas", "prefix": "R-", "next_number": 1 },
{ "id": 14, "type": "QUOTE", "code": "P", "name": "Presupuestos", "prefix": "P-", "next_number": 1 }
]
}Si recibes un 401, revisa la cabecera Authorization; si es un 403, mira el campo code del error (scope insuficiente, plan sin API…). Todos los códigos están en Errores.
3. Busca el impuesto que vas a aplicar
Los impuestos de cada línea se indican con ids del catálogo de impuestos españoles (IVA, IGIC, recargo de equivalencia, IRPF…). Búscalo una vez y guarda el id en tu configuración:
curl "https://api.billora.app/api/v1/spanish-tax-rates/?page_size=200" \
-H "Authorization: Bearer $BILLORA_API_KEY"{
"results": [
{ "id": 1, "name": "IVA General 21%", "tax_type": "IVA", "category": "incremental", "rate": "21.00", "is_active": true },
{ "id": 9, "name": "IRPF Profesionales 15%", "tax_type": "IRPF_PROF", "category": "retencion", "rate": "15.00", "is_active": true }
]
}En los ejemplos usamos 1 (IVA general del 21 %). Más detalles en Impuestos españoles.
4. Crea un cliente
curl https://api.billora.app/api/v1/customers/ \
-H "Authorization: Bearer $BILLORA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"legal_name": "Talleres Martín S.L.",
"vat_id": "B12345674",
"party_type": "company",
"email": "administracion@talleresmartin.es",
"billing_address": {
"line1": "Calle Mayor 10",
"city": "Zaragoza",
"postal_code": "50001",
"province": "Zaragoza",
"country": "ES"
}
}'import { billora } from "./billora.mjs";
const customer = await billora("POST", "/customers/", {
legal_name: "Talleres Martín S.L.",
vat_id: "B12345674",
party_type: "company",
email: "administracion@talleresmartin.es",
billing_address: {
line1: "Calle Mayor 10",
city: "Zaragoza",
postal_code: "50001",
province: "Zaragoza",
country: "ES",
},
});
console.log(customer.id);from billora import billora
customer = billora("POST", "/customers/", json={
"legal_name": "Talleres Martín S.L.",
"vat_id": "B12345674",
"party_type": "company",
"email": "administracion@talleresmartin.es",
"billing_address": {
"line1": "Calle Mayor 10",
"city": "Zaragoza",
"postal_code": "50001",
"province": "Zaragoza",
"country": "ES",
},
})
print(customer["id"])require "billora.php";
$customer = billora("POST", "/customers/", [
"legal_name" => "Talleres Martín S.L.",
"vat_id" => "B12345674",
"party_type" => "company",
"email" => "administracion@talleresmartin.es",
"billing_address" => [
"line1" => "Calle Mayor 10",
"city" => "Zaragoza",
"postal_code" => "50001",
"province" => "Zaragoza",
"country" => "ES",
],
]);
echo $customer["id"];La API responde 201 Created con el cliente completo. Antes de crear clientes desde una integración, busca primero por NIF (GET /customers/?search=B12345674) para no duplicarlos.
5. Crea la factura en borrador
Los precios van sin impuestos y los importes, como texto decimal ("85.00"). Billora calcula la base, el IVA, las retenciones y el total.
curl https://api.billora.app/api/v1/invoices/ \
-H "Authorization: Bearer $BILLORA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: pedido-2026-1042" \
-d '{
"customer": 318,
"series": 12,
"due_date": "2026-12-01",
"notes": "Pedido 2026-1042",
"lines": [
{
"description": "Revisión anual de maquinaria",
"quantity": "10",
"unit_price": "85.00",
"spanish_taxes": [1]
}
]
}'const invoice = await billora(
"POST",
"/invoices/",
{
customer: customer.id,
series: 12,
due_date: "2026-12-01",
notes: "Pedido 2026-1042",
lines: [
{ description: "Revisión anual de maquinaria", quantity: "10", unit_price: "85.00", spanish_taxes: [1] },
],
},
{ "Idempotency-Key": "pedido-2026-1042" },
);
console.log(invoice.id, invoice.status, invoice.total); // 5120 draft 1028.50invoice = billora("POST", "/invoices/", json={
"customer": customer["id"],
"series": 12,
"due_date": "2026-12-01",
"notes": "Pedido 2026-1042",
"lines": [
{"description": "Revisión anual de maquinaria", "quantity": "10",
"unit_price": "85.00", "spanish_taxes": [1]},
],
}, headers={"Idempotency-Key": "pedido-2026-1042"})
print(invoice["id"], invoice["status"], invoice["total"]) # 5120 draft 1028.50$invoice = billora("POST", "/invoices/", [
"customer" => $customer["id"],
"series" => 12,
"due_date" => "2026-12-01",
"notes" => "Pedido 2026-1042",
"lines" => [[
"description" => "Revisión anual de maquinaria",
"quantity" => "10",
"unit_price" => "85.00",
"spanish_taxes" => [1],
]],
], ["Idempotency-Key: pedido-2026-1042"]);
echo "{$invoice['id']} {$invoice['status']} {$invoice['total']}"; // 5120 draft 1028.50{
"id": 5120,
"status": "draft",
"number": null,
"customer": { "id": 318, "legal_name": "Talleres Martín S.L.", "vat_id": "B12345674" },
"series": { "id": 12, "code": "F", "name": "Facturas", "type": "INVOICE" },
"subtotal": "850.00",
"tax_total": "178.50",
"withholding_total": "0.00",
"total": "1028.50",
"balance": "1028.50",
"lines": [
{ "id": 9001, "description": "Revisión anual de maquinaria", "quantity": "10.00", "unit_price": "85.00",
"discount_percent": "0.00", "spanish_taxes": [1], "line_subtotal": "850.00", "line_tax": "178.50", "line_total": "1028.50" }
]
}La cabecera Idempotency-Key hace que, si repites la petición por un timeout, no se cree una segunda factura. Ver Idempotencia.
6. Emite la factura
Emitir asigna el número de la serie y la fecha de emisión (hoy) y registra la factura en VeriFactu. No se puede deshacer.
curl -X POST https://api.billora.app/api/v1/invoices/5120/send/ \
-H "Authorization: Bearer $BILLORA_API_KEY" \
-H "Idempotency-Key: emitir-5120"const issued = await billora("POST", `/invoices/${invoice.id}/send/`, null, {
"Idempotency-Key": `emitir-${invoice.id}`,
});
console.log(issued.number, issued.status); // F-2026-0001 sentissued = billora("POST", f"/invoices/{invoice['id']}/send/",
headers={"Idempotency-Key": f"emitir-{invoice['id']}"})
print(issued["number"], issued["status"]) # F-2026-0001 sent$issued = billora("POST", "/invoices/{$invoice['id']}/send/", null, ["Idempotency-Key: emitir-{$invoice['id']}"]);
echo "{$issued['number']} {$issued['status']}"; // F-2026-0001 sent{
"number": "F-2026-0001",
"status": "sent",
"message": "Factura enviada correctamente",
"verifactu_processed": true,
"sent_to_aeat": true
}Si VeriFactu rechaza el registro, la API responde 400, la factura sigue en borrador y no se consume número: corrige el problema (por ejemplo, el NIF del cliente) y vuelve a emitir.
7. Descarga el PDF
curl https://api.billora.app/api/v1/invoices/5120/download-pdf/ \
-H "Authorization: Bearer $BILLORA_API_KEY" \
-o F-2026-0001.pdfLa respuesta es application/pdf. También puedes enviarla al cliente por email con POST /invoices/5120/email/ y {"to": ["administracion@talleresmartin.es"]}.
8. Registra el cobro
curl https://api.billora.app/api/v1/payments/ \
-H "Authorization: Bearer $BILLORA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: cobro-5120-1" \
-d '{ "invoice": 5120, "amount": "1028.50", "currency": "EUR", "date": "2026-11-15", "reference": "Transferencia 88231" }'await billora(
"POST",
"/payments/",
{ invoice: invoice.id, amount: "1028.50", currency: "EUR", date: "2026-11-15", reference: "Transferencia 88231" },
{ "Idempotency-Key": `cobro-${invoice.id}-1` },
);
const paid = await billora("GET", `/invoices/${invoice.id}/`);
console.log(paid.status, paid.remaining_amount); // paid 0.00billora("POST", "/payments/", json={
"invoice": invoice["id"], "amount": "1028.50", "currency": "EUR",
"date": "2026-11-15", "reference": "Transferencia 88231",
}, headers={"Idempotency-Key": f"cobro-{invoice['id']}-1"})
paid = billora("GET", f"/invoices/{invoice['id']}/")
print(paid["status"], paid["remaining_amount"]) # paid 0.00billora("POST", "/payments/", [
"invoice" => $invoice["id"], "amount" => "1028.50", "currency" => "EUR",
"date" => "2026-11-15", "reference" => "Transferencia 88231",
], ["Idempotency-Key: cobro-{$invoice['id']}-1"]);
$paid = billora("GET", "/invoices/{$invoice['id']}/");
echo "{$paid['status']} {$paid['remaining_amount']}"; // paid 0.00Un cobro parcial deja la factura en partially_paid; cuando la suma de cobros cubre el total pasa a paid. Para saldar el pendiente de una vez existe POST /invoices/{id}/mark-paid/.
