REST · CLI · OpenAPI

Documentación API y CLI de SingleFax

Clave API y crédito prepago. CLI oficial de npm o ejemplos REST en curl, Node, Python, Go y PHP. Las aplicaciones de chat deben usar MCP.

CLI

npx @singlefax/cli send FILE --to +E164: envía Word, Excel, PDF o imagen original, sin convertir antes a PDF.

REST

POST /api/v1/faxes con Bearer sf_live_… y Idempotency-Key.

MCP para chat

Cursor, Claude, Codex, ChatGPT: OAuth, no clave API. Instalar MCP.

Inicio rápido

  1. Crea una clave con permisos limitados en Claves API: fax:send, fax:read, inbox:read, credits:read.
  2. Compra crédito en el panel o mediante npx @singlefax/cli credits buy.
  3. Envía con la CLI de abajo o con POST /api/v1/faxes.

URL base https://api.singlefax.com, mismas rutas en https://singlefax.com. Las claves sf_test_ no envían faxes reales. No las pongas en el navegador.

CLI

Node 20 o superior. Configuración: SINGLEFAX_API_KEY o ~/.config/singlefax/config.json. Envía el Word, Excel, PowerPoint, PDF, texto o imagen original; no conviertas antes. No sirve para MCP OAuth ni Stripe MPP.

terminal
export SINGLEFAX_API_KEY=sf_live_…

npx @singlefax/cli send ./document.docx --to +14155552671
npx @singlefax/cli send ./document.pdf --to +14155552671 --wait --json
quote, status, credits
npx @singlefax/cli quote --to +14155552671 --pages 12
npx @singlefax/cli status <id>
npx @singlefax/cli list
npx @singlefax/cli numbers
npx @singlefax/cli numbers buy
npx @singlefax/cli credits
npx @singlefax/cli credits buy --dollars 20

Enviar un fax

Una solicitud: documento en base64 y destino. PDF, Word, Excel, PowerPoint, texto o imágenes. Idempotency-Key es obligatorio. Reutilizar una clave con otro cuerpo devuelve 409.

terminal
PDF_B64="$(base64 < document.pdf | tr -d '\n')"

curl -sS https://api.singlefax.com/api/v1/faxes \
  -H "Authorization: Bearer $SINGLEFAX_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d "{\"to\":\"+14155552671\",\"base64\":\"$PDF_B64\"}"

Archivos grandes: subir y después enviar

La CLI crea un token de subida, carga los datos con PUT y envía con uploadToken. PUT también requiere Bearer. Es preferible a incluir un archivo grande en JSON. No conviertas antes a PDF.

terminal
UPLOAD=$(curl -sS https://api.singlefax.com/api/v1/uploads \
  -H "Authorization: Bearer $SINGLEFAX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contentType":"application/pdf"}')

UPLOAD_URL=$(printf '%s' "$UPLOAD" | python3 -c "import json,sys; print(json.load(sys.stdin)['uploadUrl'])")
TOKEN=$(printf '%s' "$UPLOAD" | python3 -c "import json,sys; print(json.load(sys.stdin)['uploadToken'])")

curl -sS -X PUT "$UPLOAD_URL" \
  -H "Authorization: Bearer $SINGLEFAX_API_KEY" \
  -H "Content-Type: application/pdf" \
  --data-binary @document.pdf

curl -sS https://api.singlefax.com/api/v1/faxes \
  -H "Authorization: Bearer $SINGLEFAX_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d "{\"to\":\"+14155552671\",\"uploadToken\":\"$TOKEN\"}"

Referencia REST

MétodoRutaAutenticaciónNotas
POST/api/v1/faxesfax:sendIdempotency-Key required. JSON { to, base64 | uploadToken } or multipart file.
GET/api/v1/faxesfax:readList. Query limit, offset.
GET/api/v1/faxes/{id}fax:readStatus including latest delivery attempt.
POST/api/v1/faxes/quotefax:read{ to, pages? | base64? }, quote without charging.
POST/api/v1/uploadsfax:sendReturns uploadToken + uploadUrl. PUT the bytes, then send with uploadToken.
GET/api/v1/creditscredits:readPrepaid balance.
POST/api/v1/credits/checkoutcredits:checkout{ amountCents }. Stripe Checkout for a credit pack.
GET/api/v1/received-faxesinbox:readInbound inbox list. Query limit, cursor. No transcripts in list.
GET/api/v1/received-faxes/{id}inbox:readInbound detail with bounded transcript slice. HIPAA Secure content is omitted.
GET/api/v1/numbersfax:readActive fax numbers.
POST/api/v1/numberscredits:checkout{ sku?, country?, state? }, default inbound_30day. Returns checkoutUrl + reserved phoneNumber.
GET/api/v1/skuspublicCatalog. Same shape as MCP list_skus.
POST/api/v1/checkoutcredits:checkout{ sku }, credit_pack, inbound, subscriptions, lifetime.

Esquemas completos: openapi.json. Cambios incompatibles: política de versiones, Sunset de 90 días. HTTP 402 en esta API significa saldo insuficiente. MPP 402 solo se usa en POST /api/v1/machine/faxes.

Webhooks

Eventos firmados fax.queued, fax.delivered, fax.failed y credits.low_balance. Verifica SingleFax-Signature, t=,v1=, con el cuerpo original. HMAC-SHA256 de timestamp.payload. Añade el endpoint en webhooks del panel.

verify.mjs
import { createHmac, timingSafeEqual } from 'node:crypto'

export function verifySingleFaxSignature(rawBody, signatureHeader, secret, toleranceSeconds = 300) {
  const parts = Object.fromEntries(signatureHeader.split(',').map((kv) => kv.split('=')))
  const timestamp = Number(parts.t)
  if (!Number.isFinite(timestamp) || !parts.v1) return false
  if (Math.abs(Math.floor(Date.now() / 1000) - timestamp) > toleranceSeconds) return false
  const expected = createHmac('sha256', secret).update(`${timestamp}.${rawBody}`).digest('hex')
  const a = Buffer.from(parts.v1)
  const b = Buffer.from(expected)
  return a.length === b.length && timingSafeEqual(a, b)
}

Limitaciones

  • Guarda las claves API en el servidor. No incluyas sf_live_ en una web.
  • No envíes PHI. Las entidades sujetas a HIPAA usan HIPAA Secure en la web con BAA electrónico.
  • Destinos E.164 válidos. PDF, Word, Excel, PowerPoint, RTF, texto e imágenes; consulta MIME en OpenAPI. No conviertas antes a PDF: lo hacemos antes de enviar.
  • MCP de chat y Stripe MPP: /agents, mpp.md y MPP o pago inmediato.

Preguntas frecuentes

Documentación legible por máquinas

Markdown sencillo y OpenAPI para rastreadores y agentes de programación. Los mismos datos que esta página.