Integration Debugging Playbook
When the API call, webhook, or auth handshake fails at the customer’s edge — the systematic checklist that finds it fast.
Integration bugs live in the gap between systems you do not fully control: your code, the customer’s network and a third-party API. The fastest way through is to stop guessing and move layer by layer (DNS, then TCP and TLS, then authentication, then the payload), confirming each before blaming the next, and to reproduce from the machine that actually fails rather than from your laptop.
Every step should leave evidence: the exact request, the status code, the response body and the request ID. That evidence is also what gets a vendor’s support team to take you seriously.
Read the status code
- 401 / 403
- Auth. Wrong/expired token, missing scope, or IP not allow-listed. Check the exact header.
- 404
- Wrong URL/base path or the resource isn’t there yet. Sandbox vs prod host?
- 400 / 422
- their validation rejected the payload — read the error body and diff it against the schema
- 409
- conflict: a reused idempotency key, a version mismatch, or the resource already exists
- 3xx
- a redirect your client didn’t follow (
curl -L), often HTTP → HTTPS; POST may turn into GET - 429
- Rate limited. Back off (jitter), check
Retry-After, batch requests. - 5xx
- Their side (or a proxy). Retry idempotent calls; capture request-id; escalate with it.
- Timeout / no response
- Firewall/egress, DNS, or wrong port. Try
curl -vfrom the deploy host.
Auth handshake
- Token in the right place
- Header vs query vs body.
Authorization: Bearer …— exact casing/prefix. - Clock skew
- Signed requests / JWT fail if the server clock is off. Sync NTP.
- Scopes / audience
- Token valid but lacks the scope, or wrong
audfor this API. - mTLS / cert
- Customer requires a client cert? Verify chain + that it’s actually being sent.
- Token refresh
- an access token expired mid-run; refresh before expiry and retry once on 401
- Wrong environment key
- a sandbox key against production, or the reverse — the most common 401 of all
DNS, TLS & network
- dig +short api.host
- does the name resolve from the deploy host, and to the IP you expect?
- nc -zv api.host 443
- TCP reachability in one line — separates network blocks from app errors
- openssl s_client
-connect host:443 -servername hostshows the certificate chain and handshake errors- Expired certificate
- yours or theirs; the validity dates are in the
s_clientoutput - TLS-inspecting proxy
- a corporate proxy swaps certificates — trust its CA or exclude the host via
NO_PROXY - IP allow-lists
- their firewall must allow your egress IPs, which NAT gateways and serverless platforms can change
Payloads & encoding
- Content-Type mismatch
- JSON sent as form-encoded, or the reverse — the server sees an empty payload
- Character encoding
- non-UTF-8 input mangles names; normalize to UTF-8 at the edge
- Dates & time zones
- send ISO 8601 with an offset, e.g.
2026-10-22T09:00:00Z; naive local times drift by hours - Large integer IDs
- IDs above 2⁵³ lose precision in JavaScript — carry them as strings
- Pagination
- follow the cursor until it is empty, and count distinct IDs to prove nothing was skipped
- Null vs missing
- many APIs treat an explicit
nulldifferently from an omitted field
Retries, limits & timeouts
- Exponential backoff
- retry with growing, jittered delays; stop at a cap and surface the error
- Retry-After
- when present on a 429 or 503, wait exactly that long before retrying
- Idempotency keys
- one per logical operation, so a retried POST cannot charge or create twice
- Timeout budget
- set connect and read timeouts below your caller’s own timeout, or retries pile up
- Batch over loop
- one bulk call instead of a thousand single calls keeps you under rate limits
Webhooks (inbound)
- Signature mismatch
- Verify over the raw body (not re-serialized JSON); use the right secret + algorithm.
- Reachability
- Is your endpoint public + TLS? Use their delivery log / a request-bin to confirm arrival.
- Duplicates / retries
- They retry on non-2xx. Be idempotent; ack fast (2xx) then process async.
- Replay window
- Reject events older than N minutes to stop replay attacks.
- Out-of-order events
- deliveries arrive in any order — use event timestamps or versions, not arrival order
- Test locally
- expose localhost through a tunnel, or resend events from the provider’s dashboard
Isolate the layer
- curl from the box
- Reproduce from the actual deploy host — not your laptop. Egress rules differ.
- Log the request-id
- Most APIs return one. It’s your ticket when you escalate to their team.
- Binary-search the stack
- DNS → TCP/TLS → auth → payload. Confirm each layer before blaming the next.
- Diff working vs broken
- A Postman call that works vs your code that doesn’t → compare headers byte-for-byte.
- Change one thing
- swap only the token, or only the payload, between attempts — otherwise you learn nothing
Escalate with evidence
- Request ID + timestamp
- the exact UTC time and request ID are what their support needs to find your call
- Minimal curl repro
- one failing command with secrets redacted beats a paragraph of description
- Expected vs actual
- what you sent, what you expected and what came back, headers included
- Impact
- how many calls or customers are affected, and since when
Worked example: webhooks that pass in staging and fail in production
Payment webhooks have failed in production since Tuesday’s deploy. Staging still passes. Every delivery gets 400 invalid signature from your handler.
- Read the provider’s delivery log first. Events reach you, and your server answers 400. So DNS, TCP and TLS all work, and you can skip three layers on evidence rather than hope.
- Rule out the secret. Production has its own webhook endpoint with its own secret. The last four characters of the configured secret match the dashboard.
- Compare the bytes. Log the length of the raw request body and of the string your code signs: 31 against 28. Tuesday’s deploy added a JSON body parser in front of every route, so the handler now signs
JSON.stringify(req.body).
received: {"id": "evt_1", "amount": 1200} 31 bytes HMAC 3bd7f62911eb7455…
signed: {"id":"evt_1","amount":1200} 28 bytes HMAC 333b3dda9766f4bf…
Same data, different bytes, different signature (HMAC-SHA256 with the secret whsec_test, first 16 hex digits shown). The fix is to give the webhook route the raw body, in Express with express.raw({ type: 'application/json' }) on that route, and parse the JSON only after the signature checks out.
Two follow-ups before closing the incident. The provider retries non-2xx deliveries, so a backlog of retries is about to arrive: deduplicate on the event ID so nothing is processed twice. And if your replay window checks the event’s creation time instead of the signed delivery timestamp, every retried event from Tuesday will now be rejected as a replay.
Recipes
Walk the layers from the deploy host
dig +short api.vendor.com
nc -zv api.vendor.com 443
openssl s_client -connect api.vendor.com:443 -servername api.vendor.com < /dev/null | head -20
curl -sv -H "Authorization: Bearer $TOKEN" https://api.vendor.com/v1/pingEach line tests one layer: name resolution, TCP reachability, the TLS handshake and certificate, then authentication and the HTTP response. The first line that fails is where to look.
Verify a webhook signature over the raw body (Python)
import hashlib, hmac
def verify(raw_body: bytes, header_sig: str, secret: str) -> bool:
expected = hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, header_sig)Sign the bytes exactly as received, since re-serialized JSON changes whitespace and key order; match the provider’s encoding too (hex or base64, any sha256= prefix).
Retry with backoff and an idempotency key (Python)
import random, time, uuid
import requests
def post_with_retry(url, payload, attempts=5):
key = str(uuid.uuid4())
for i in range(attempts):
r = requests.post(url, json=payload, timeout=(3, 10),
headers={"Idempotency-Key": key})
if r.status_code not in (429, 500, 502, 503, 504):
return r
delay = float(r.headers.get("Retry-After", 2 ** i))
time.sleep(delay + random.uniform(0, 1))
r.raise_for_status()
return rThe same key on every attempt lets the server drop duplicates, a Retry-After in seconds overrides the computed delay, and jitter stops many clients retrying in lockstep.
An escalation note a vendor can act on
Subject: 401 on POST /v1/orders since 2026-10-22 08:10 UTC (production)
Request ID: req_8f3a2c (41 more attached)
Time: 2026-10-22T08:14:03Z
Repro: curl -sv -X POST https://api.vendor.com/v1/orders -H "Authorization: Bearer [redacted]" --json @order.json
Expected: 201 Created, as on 2026-10-21
Actual: 401 {"error":"invalid_token"}; the same key works on GET /v1/ping
Impact: all order creation for 3 customers since 08:10 UTCPrecise times, request IDs, a one-line repro and the impact let their engineers find your traffic in their logs without a single follow-up question.
When to use it, and when not
Use the layer walk whenever a call across a system boundary fails and the error body does not already name the cause: a new customer environment, a vendor API that “stopped working”, a webhook that never arrives, anything that works on your laptop and fails on the server.
- Read the error body first. A 422 that names the missing field needs no layer walk.
- Check the vendor’s status page when a call that worked yesterday now fails for everyone at once. A widespread 5xx is theirs.
- Reach for a packet capture (tcpdump, Wireshark) only when the walk stalls at TCP or TLS and the error messages disagree. It needs access you often will not have on a customer’s machine.
- Switch to tracing for intermittent slowness across many services. The layer walk finds calls that break, not calls that are slow.
Trade-offs and limits
| Technique | Finds | Misses |
|---|---|---|
| curl from the deploy host | network, TLS and auth as the server sees them | bugs in how your own code builds the request |
| Diff a working and a broken request | header and payload differences | environment differences such as egress or DNS |
| Vendor delivery or request logs | whether the call arrived, and their status code | anything that failed before it reached them |
| Retries with backoff | transient failures | permanent ones, which they only delay |
Every retry and timeout setting is a trade. Longer timeouts and more attempts ride out brief outages, but they hold connections and workers and can pile up behind a slow dependency. Keep the total retry time below what your own caller is willing to wait.
Common mistakes
- Testing from your laptop. It has different DNS, no corporate proxy and a different egress IP. A curl that works there proves very little about the server.
- Retrying 4xx errors. A 400 or 401 fails the same way every time. Retries only multiply log noise and can trip rate limits. Retry timeouts, 429 and 5xx.
- Logging the token to debug auth. Then it lives in your log store indefinitely. Log its prefix, its length and its decoded claims (
exp,aud, scopes) instead. - Turning off TLS verification “to get past it”.
curl -korverify=Falsemakes the error disappear and the interception risk real. Trust the right CA instead. - Parsing large IDs as numbers. In JavaScript,
JSON.parse('{"id": 9007199254740993}').idreturns9007199254740992, which is a different record. Keep IDs as strings. - Changing three things at once. A new token, URL and payload in one attempt. If it works, nobody knows why; if it fails, nobody knows which change did it.
Check yourself
From the deploy host, curl -v prints Trying 203.0.113.10:443... and then times out. dig resolves fine. Which layer is it, and what do you do next?
TCP. The name resolves but the connection never opens, which points to a firewall, an egress rule or an allow-list. Confirm with nc -zv host 443, then ask their network team to allow your egress IP (IP allow-lists). Auth cannot be the problem yet: no request has been sent.
A token copied from the vendor’s sandbox dashboard gets 401 from https://api.vendor.com, the production host. What is the likely cause?
Wrong environment key, the most common 401 of all. Use the production key, or point the client at the sandbox host. Nothing below the auth layer needs checking: a 401 means DNS, TCP and TLS all worked.
A POST to create a charge timed out. The retry, sent with the same idempotency key, got 409. Should you retry with a new key?
No. The 409 says the server already holds a request with that key, possibly the first attempt still running or already finished (409, Idempotency keys). A new key is how a customer gets charged twice. Wait and retry with the same key, or look the charge up.
A Node service stores an order ID of 9007199254740993 from a JSON response, then cannot find the order. Why?
Numbers above 2⁵³ (9,007,199,254,740,992) lose precision in JavaScript, so JSON.parse turns the ID into 9007199254740992. Carry such IDs as strings (Large integer IDs).
Questions about Integration Debugging Playbook
How do I debug a 401 Unauthorized error from an API?
Check the basics in order. Confirm the key or token belongs to the right environment, since a sandbox key used against production is the most common cause. Look at the exact header: its name, the Bearer prefix, and no stray whitespace or quotes. Decode a JWT to check its expiry, audience and scopes, and make sure the server clock is correct, because skew invalidates signed requests. Then reproduce with curl from the same host; if curl succeeds and your code fails, compare the two requests header by header.
Why does webhook signature verification fail?
Almost always because the signature was computed over different bytes from the ones the provider signed. Frameworks often parse the JSON body before your handler runs, and serializing it again changes whitespace, key order or Unicode escaping, so verify against the raw request body exactly as it arrived. Other causes are the wrong secret, often one from a different environment or endpoint, the wrong algorithm or encoding such as hex versus base64, a timestamp missing from the signed string, and reading the wrong header.
What is the difference between a 401 and a 403 error?
A 401 Unauthorized means the request was not authenticated: credentials were missing, expired or could not be verified, and the response should include a WWW-Authenticate header describing how to authenticate. A 403 Forbidden means the server knows who you are but you are not allowed to do this, because of missing scopes or roles, an IP allow-list or an account restriction. So for a 401, fix the credential itself, and for a 403, fix the permissions attached to it. Some APIs blur the two, so read the error body as well.
How should I retry failed API calls?
Retry only failures that are likely to be transient, such as timeouts, connection resets, 429 and 502 to 504, and never client errors such as 400 or 401. Use exponential backoff with random jitter, honor Retry-After when the server sends it, and cap both the number of attempts and the total time. Make retried writes safe with an idempotency key, so a request that succeeded but timed out is not applied twice. Finally, log every retry: a steadily rising retry rate is often the first sign of an outage.