← Back to all engineering articles

The Two-Way Webhook Trap: Debugging Twilio SMS, TwiML, and Fallbacks

Setting up a Twilio SMS or Voice integration usually hits the same speed bump: Twilio needs a public HTTPS URL before it can send you a single event, and you want to see the real form fields and headers before writing half your backend. Spinning up a local tunnel or deploying a temporary server works, until your laptop goes to sleep or you need to test what happens when your endpoint returns an error.

With SnapHook, you can generate a live webhook endpoint in two seconds, inspect Twilio's exact requests in real time, return valid TwiML so Twilio's debugger stays green, and even simulate 500 failures to test your fallback URLs.

Why Twilio Webhooks Need More Than a Plain Request Bin

A Twilio webhook is a two-way conversation: Twilio sends your server an HTTP request (usually a POST with application/x-www-form-urlencoded fields such as From, To, Body, and MessageSid), and for incoming calls or messages, Twilio pauses and waits for valid TwiML (Twilio Markup Language) XML in the response body.

That second part trips up most generic request bins. If a capture endpoint always replies with JSON like {"ok":true}, Twilio logs a content-type or XML parse warning in the Twilio Console Debugger even though the HTTP status was 200 OK. Because SnapHook lets you customize the response status, Content-Type, and body per session, it works cleanly with every Twilio callback type:

[Twilio] ── POST /w/<slug>/twilio/sms ──► [SnapHook] ──► Live SSE Dashboard (/app/<slug>)
                                               │
                                    200 OK + TwiML XML
                                  (or 500 to test fallback)

Step 1: Create a SnapHook Endpoint in Two Seconds

You do not need an account, CLI, or SDK to start capturing Twilio events. Pick whichever option fits your workflow:

curl -s -X POST https://snaphook.site/api/new
{
  "expires_at": "2026-11-29T13:30:00Z",
  "expires_in_seconds": 7200,
  "id": "iszus5e52fbp",
  "url": "/app/iszus5e52fbp",
  "webhook_url": "https://snaphook.site/w/iszus5e52fbp"
}

Keep the /app/{slug} tab open in your browser. As explained in SnapHook's URL anatomy guide, anything sent to /w/{slug} streams into that tab instantly over Server-Sent Events (SSE), with no polling or page refreshes required.

Step 2: Point Twilio at Distinct Subpaths

One SnapHook URL can capture multiple Twilio callbacks without mixing them together. SnapHook accepts any HTTP method and any subpath under /w/{slug}/..., then strips the session prefix so the inspector displays the clean callback path you configured.

For example, given the base webhook URL https://snaphook.site/w/iszus5e52fbp, you can wire up Twilio like this:

In the Twilio Console, open Phone Numbers → Manage → Active numbers, select your test number, and paste the subpath URL into the Messaging or Voice webhook field. You can read more about how Twilio formats these callbacks in the Twilio Webhooks documentation and the Twilio Messaging Webhook Request guide.

Step 3: Return Valid TwiML So Twilio Stays Happy

If you only attach a StatusCallback URL, Twilio ignores the response body as long as it receives an HTTP 200 OK. For incoming SMS or Voice webhooks, however, Twilio expects XML formatted as TwiML.

To configure SnapHook to answer with TwiML instead of its default JSON acknowledgement, open the Response dialog in your SnapHook inspector and click the 200 XML preset (which fills in status 200, Content-Type: application/xml; charset=utf-8, and an empty <Response></Response> body), or update it via the API with application/xml; charset=utf-8 (or text/xml; charset=utf-8) and your TwiML document.

Option A: Acknowledge Silently With an Empty Response

When you want to capture an incoming SMS without texting anything back to the sender, return an empty <Response/>:

SLUG=iszus5e52fbp

curl -X PUT "https://snaphook.site/api/$SLUG/response" \
  -H 'Content-Type: application/json' \
  -d '{
    "status": 200,
    "content_type": "application/xml; charset=utf-8",
    "body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response/>"
  }'

Option B: Reply With an Automated Message

To verify an end-to-end SMS round trip, return a <Message> element as documented in the Twilio Messaging TwiML reference:

curl -X PUT "https://snaphook.site/api/$SLUG/response" \
  -H 'Content-Type: application/json' \
  -d '{
    "status": 200,
    "content_type": "application/xml; charset=utf-8",
    "body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><Message>Received by SnapHook!</Message></Response>"
  }'

Check your Content-Type header:

Make sure Content-Type is explicitly set to application/xml; charset=utf-8 or text/xml; charset=utf-8 alongside your TwiML body. If a session uses the default application/json; charset=utf-8 response, Twilio's debugger flags an XML parse warning even on HTTP 200 OK.

Step 4: Inspect Real Payloads and Debug X-Twilio-Signature

Send a text message to your Twilio number (or trigger an outbound message with StatusCallback set to your SnapHook URL). Within a second, the request appears in your SnapHook inspector with four sections:

Comparing the captured X-Twilio-Signature, query string, and raw POST parameters against what your own backend receives is one of the fastest ways to diagnose signature-validation bugs (often caused by reverse proxies stripping HTTPS or altering paths before your app validates the request). For implementation details, see Twilio's Securing Webhooks guide and our Webhook Security Primer.

Step 5: Test Fallback URLs Safely

Once the happy path works, test what Twilio does when your server breaks. Because SnapHook records incoming requests before writing the response, you can configure an error status and still inspect every attempt in the inspector.

# Force SnapHook to reply 500 so Twilio triggers your Fallback URL
curl -X PUT "https://snaphook.site/api/$SLUG/response" \
  -H 'Content-Type: application/json' \
  -d '{"status":500,"content_type":"text/plain","body":"simulated outage"}'

Send another test SMS or call and verify in the Twilio Console Debugger that Twilio logs the 500 error and immediately invokes your configured Primary Handler Fails fallback URL.

When you are done testing failures, click Reset to default in the Response dialog or call DELETE /api/{slug}/response (see the SnapHook FAQ and our guide to webhook retries and backoff for broader resilience patterns).

Limits and Security Hygiene to Keep in Mind

Before wiring up a sandbox or staging integration, check these practical boundaries from SnapHook's limits and security notes:

Ready to try it?

Generate a capture URL on snaphook.site, set your response type to application/xml; charset=utf-8 with <Response/>, and point a Twilio test number at /w/{slug}/twilio/sms. You can review all configuration options anytime in the SnapHook Docs and the Twilio Webhooks Guide.


Inspect your webhooks live in 2 seconds

No signup required. SnapHook creates a dedicated URL, streams incoming HTTP payloads over SSE, and lets you customize synthetic status codes and latency.