GuíaEjemplosReferencia API
apisunat.netIngresar
  • Factura
  • Boleta
  • Nota de crédito
  • Nota de débito
  • Retención
  • Percepción
  • Liquidación de compra
  • Anulaciones
  • Guía de remisión
  • Descargas
  • Node, PHP y Python

Node, PHP y Python

Emitir una factura y verificar un webhook desde tu lenguaje.

La API es REST con JSON: no necesitas un SDK. Estos ejemplos usan solo la librería estándar o el cliente HTTP más común de cada lenguaje.

Emitir una factura

js
// Node 18+ (fetch nativo)
import { randomUUID } from "node:crypto";

const response = await fetch("https://api.apisunat.net/api/v1/issuer/documents", {
  method: "POST",
  headers: {
    "X-API-Key": process.env.APISUNAT_KEY,
    "Idempotency-Key": randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    documentType: "01",
    currency: "PEN",
    issueDate: "2026-10-27",
    customer: { documentType: "6", documentNumber: "20100066603" },
    items: [{ description: "Consultoría", quantity: 1, unitPrice: 1180, unitCode: "ZZ" }],
  }),
});
const body = await response.json();
if (!response.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
console.log(body.fullNumber, body.status);

Guarda el Idempotency-Key junto a tu pedido y reúsalo si reintentas: así un reintento nunca emite dos veces. Ver Idempotencia.

Verificar un webhook

La verificación de la firma en Node.js, PHP y Python está en Webhooks.

Descargas< Previous

Powered by heyo

On this page

Emitir una facturaVerificar un webhook