Skip to main content

Outcome

You will send a fax to a sandbox magic number, poll for its status, receive a webhook event, and verify the HMAC signature. Everything runs against the sandbox. No real faxes are sent and no credits are charged.

Prerequisites

  • A mintfax sandbox API key (mfx_test_...). Sign up here if you do not have one.
  • Node.js 18 or later (for native fetch and crypto).
  • A PDF file to fax. Any single-page PDF works.
  • A publicly reachable URL for webhooks, or a tunnel tool such as ngrok.

Step 1: Send a fax

Post a fax to the sandbox success number +15005550001. This number always delivers on the first attempt. Create send-fax.mjs:
Run it:
Verify: The response status is 201 and the status field is queued. Save the returned id for the next step. The Idempotency-Key header makes this request safe to retry. If the network drops and you re-run the same script, mintfax returns the original response without sending a duplicate fax. See Idempotency keys for details.

Step 2: Check fax status

Poll GET /fax/{id} until the fax reaches a terminal state (delivered or failed). Create check-status.mjs:
Run it with the fax ID from step 1:
Verify: The sandbox success number delivers within seconds. You should see delivered printed to the console.

Step 3: Receive a webhook event

mintfax sends a fax.delivered or fax.failed event to your webhook URL when a fax reaches a terminal state. The server below listens for these events and verifies the HMAC signature before trusting the payload. Create webhook-server.mjs:
Start the server, then expose it with ngrok (or any tunnel):
Copy the ngrok HTTPS URL and register it as your environment’s webhook endpoint in the mintfax dashboard or via the API. Send another fax (step 1). The event arrives within seconds of delivery. Verify: The console prints Received fax.delivered for fax <id> and the signature check passes. The Webhook signing guide covers replay protection, secret rotation, and signature verification in other languages.

Step 4: Handle errors

Swap the destination number in send-fax.mjs to trigger different outcomes: The fax record’s error_code and error_message fields tell you what went wrong and whether a retry makes sense. See the Error catalog for every error code and its recommended action. The Sandbox guide lists all magic numbers and the scenarios they simulate.

Verify

You have now:
  1. Sent a fax with POST /fax and an idempotency key.
  2. Polled for status until delivery.
  3. Received a webhook event and verified its HMAC signature.
  4. Triggered error scenarios with sandbox magic numbers.
Everything above ran in the sandbox. To send real faxes, swap your sandbox key for a live key (mfx_live_...), purchase credits, and use a real fax number as the destination.

What to do next

  • Webhook signing - replay protection, secret rotation, and verification in other languages.
  • Idempotency keys - how keys are stored and matched, TTL behavior, and retry best practices.
  • Error catalog - every error code, its trigger, and the recommended action.
  • Events schema - all event types and their payload shapes.
  • Sandbox - magic numbers, simulated failures, and sandbox behavior.
Last modified on July 17, 2026