REST · CLI · OpenAPI

SingleFax-API-Dokumentation und CLI

API-Schlüssel plus Prepaid-Guthaben. Offizielle npm-CLI oder direkt nutzbare REST-Beispiele für curl, Node, Python, Go und PHP. Chat-Apps sollten MCP verwenden.

CLI

npx @singlefax/cli send FILE --to +E164, mit originaler Word-, Excel-, PDF- oder Bilddatei, ohne vorherige PDF-Konvertierung.

REST

POST /api/v1/faxes mit Bearer sf_live_… und einem Idempotency-Key.

Chat-MCP

Cursor, Claude, Codex, ChatGPT. OAuth statt API-Schlüssel. MCP installieren.

Schnellstart

  1. Erstellen Sie unter API-Schlüssel einen Schlüssel mit passenden Berechtigungen (fax:send, fax:read, inbox:read, credits:read).
  2. Guthaben im Kundenkonto vorausbezahlen oder npx @singlefax/cli credits buy.
  3. Mit der CLI unten oder POST /api/v1/faxes senden.

Basis-URL https://api.singlefax.com, dieselben Pfade auf https://singlefax.com. sf_test_-Schlüssel können nicht live senden. Schlüssel nicht im Browser hinterlegen.

CLI

Node 20+. Konfiguration: SINGLEFAX_API_KEY oder ~/.config/singlefax/config.json. Originaldatei übergeben (Word, Excel, PowerPoint, PDF, Text oder Bild), nicht vorher in PDF umwandeln. Nicht für MCP-OAuth oder 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

Fax senden

Eine Anfrage: Base64-Dokument plus Zielnummer. PDF, Word, Excel, PowerPoint, Text oder Bilder. Idempotency-Key ist erforderlich. Derselbe Schlüssel mit anderem Anfrageinhalt ergibt 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\"}"

Größere Dateien: hochladen, dann senden

So arbeitet die CLI: Uploadtoken erstellen, Dateidaten per PUT hochladen, dann mit uploadToken senden. Auch PUT benötigt den Bearer-Token. Für große Dateien ist dies besser als JSON. Nicht vorher in PDF umwandeln.

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\"}"

REST-Referenz

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

Vollständige Schemas: openapi.json. Inkompatible Änderungen: Versionierungsrichtlinie mit 90 Tagen Sunset-Frist. HTTP 402 bei dieser Guthaben-API bedeutet unzureichendes Guthaben. MPP-402 gilt nur für POST /api/v1/machine/faxes.

Webhooks

Signierte Ereignisse fax.queued, fax.delivered, fax.failed und credits.low_balance. Prüfen Sie SingleFax-Signature (t=,v1=) anhand des unveränderten Anfragekörpers. HMAC-SHA256 von timestamp.payload. Endpunkt unter Webhooks im Kundenkonto hinzufügen.

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

Rahmenbedingungen

  • API-Schlüssel auf dem Server halten. sf_live_ nicht in Webseiten einbetten.
  • Keine PHI senden. HIPAA-pflichtige Einrichtungen nutzen HIPAA Secure Mode auf der Website mit elektronischem BAA.
  • Gültige E.164-Zielnummern. PDF, Word, Excel, PowerPoint, RTF, Klartext und Bilder; MIME-Typen siehe OpenAPI. Nicht vorher in PDF umwandeln, das übernehmen wir vor dem Versand.
  • Chat-MCP und Stripe MPP: /agents, mpp.md und MPP oder Instant Checkout.

Häufige Fragen

Maschinenlesbare Dokumentation

Markdown und OpenAPI für Crawler und Coding-Agenten. Dieselben Fakten wie auf dieser Seite.