REST · CLI · OpenAPI

Documentazione API e CLI SingleFax

Chiave API e crediti prepagati. CLI ufficiale npm o esempi REST pronti per curl, Node, Python, Go e PHP. Le chat usano invece MCP.

CLI

npx @singlefax/cli send FILE --to +E164, passando Word, Excel, PDF o immagine originali, senza conversione preventiva.

REST

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

MCP per chat

Cursor, Claude, Codex, ChatGPT. OAuth, non chiave API. Installa MCP.

Avvio rapido

  1. Crea una chiave con permessi limitati su Chiavi API (fax:send, fax:read, inbox:read, credits:read).
  2. Acquista crediti nel pannello o tramite npx @singlefax/cli credits buy.
  3. Invia con la CLI sotto o POST /api/v1/faxes.

URL base https://api.singlefax.com (stessi percorsi su https://singlefax.com). Le chiavi sf_test_ non inviano realmente. Non mettere chiavi nel browser.

CLI

Node 20+. Configurazione: SINGLEFAX_API_KEY o ~/.config/singlefax/config.json. Passa il file originale (Word, Excel, PowerPoint, PDF, testo o immagine), senza convertirlo prima. Non per MCP OAuth o 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

Invia un fax

Una richiesta: documento base64 e destinazione. PDF, Word, Excel, PowerPoint, testo o immagini. Idempotency-Key obbligatorio. Riutilizzare una chiave con corpo diverso restituisce 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\"}"

File grandi: carica, poi invia

La CLI crea un token di caricamento, esegue PUT dei byte e invia con uploadToken. Anche PUT richiede Bearer. Preferiscilo a grandi file nel JSON. Non convertire prima in 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\"}"

Riferimento REST

MetodoPercorsoAutenticazioneNote
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.

Schemi completi: openapi.json. Modifiche incompatibili: politica delle versioni (Sunset di 90 giorni). HTTP 402 su questa API crediti significa saldo insufficiente; MPP 402 è solo POST /api/v1/machine/faxes.

Webhook

Eventi firmati fax.queued, fax.delivered, fax.failed, credits.low_balance. Verifica SingleFax-Signature (t=,v1=) sul corpo originale. HMAC-SHA256 di timestamp.payload. Aggiungi un endpoint in webhook del pannello.

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)
}

Vincoli

  • Conserva le chiavi sul server. Non incorporare sf_live_ in una pagina web.
  • Non inviare PHI. Gli enti soggetti usano HIPAA Secure sul sito con BAA elettronico.
  • Destinazioni E.164 valide. PDF, Word, Excel, PowerPoint, RTF, testo e immagini: MIME in OpenAPI. Non convertire prima in PDF, lo facciamo prima dell’invio.
  • MCP chat e Stripe MPP: /agents, mpp.md, MPP e Instant Checkout a confronto.

Domande frequenti

Documentazione leggibile dalle macchine

Markdown semplice e OpenAPI per crawler e agenti di programmazione. Stesse informazioni della pagina.