How to Debug an API Request
Debug an API request in order rather than by guessing. Read the status code first — it tells you whose problem it is. Then check the response headers, decode the token if authentication failed, and only then examine the request body. Working outside in stops you rewriting a payload when the real problem was an expired token.
HTTP Header Parser
Turn a raw header block into a readable table.
Most time lost to a failing API call goes on checking things in the wrong order — rewriting the request body when the token had expired, or hunting for a permissions bug when the URL was wrong. The status code narrows it down immediately, and each class of code points at a different part of the request.
The order below is outside in: transport, then authentication, then content. Each step is cheap, and each one eliminates a whole category of cause.
Step by step
-
Read the status code first
A 4xx means the request was wrong; a 5xx means the server failed handling it. That single distinction decides whether you are debugging your call or reporting a bug. 401 is unauthenticated, 403 is authenticated but not permitted, 404 may be a wrong path or a resource you cannot see, 422 usually means the body parsed but failed validation.
-
Check the response headers
Paste the raw block into a header parser. Look for Retry-After on a 429, WWW-Authenticate on a 401, and Content-Type — a JSON parse error is often an HTML error page arriving where you expected JSON.
-
Confirm the URL is what you think
Parse it. A missing trailing path segment, a query parameter that was never encoded, or a request to the wrong environment are all invisible in code and obvious once the URL is split apart. Check for a redirect too: a POST that gets redirected may arrive as a GET with no body.
-
Decode the token if authentication failed
For a 401, decode the JWT and check exp first — an expired token is the most common cause by a wide margin. Then check iss and aud match what the API expects. Remember JWT timestamps are seconds, not milliseconds.
-
Validate the request body
Only once transport and auth are ruled out. Format the JSON to confirm it is well formed, then validate it against the endpoint's schema if one is published. A 422 with a vague message usually resolves into a single wrong type or missing field.
-
Diff a working request against the failing one
When everything looks correct, capture a request that works and compare the two payloads field by field. The difference is usually somewhere you were not looking, and a diff finds it faster than reading both.
Example
Working outside in: three cheap checks before touching the payload.
Symptom
POST /v1/orders
→ 401 Unauthorized
Order to check
1. Status 401 → authentication, not payload
2. Headers → WWW-Authenticate says why
3. Decode token → exp in the past
4. Refresh the token; payload untouched
Frequently asked questions
What is the difference between 401 and 403?
Why does my JSON parser fail on the response?
My POST is arriving with no body. Why?
The token looks valid but the API rejects it. What now?
Is it safe to paste a real token into a decoder?
Tools used in this guide
All tools →- HTTP Header Parser Turn a raw header block into a readable table. In your browser
- HTTP Status Code Reference Search every HTTP status code and what it means. In your browser
- JWT Decoder Read a JSON Web Token header, payload and expiry. In your browser
- JSON Formatter Beautify, validate and sort JSON with precise error messages. In your browser
- JSON Schema Validator Check a JSON document against a JSON Schema and see every failure. In your browser
- URL Parser Split a URL into its scheme, host, path, query and fragment. In your browser
- JSON Diff Compare two JSON documents and see exactly what changed. In your browser
Related guides
All guides →- How to Decode a JWT Read the header and payload of a JSON Web Token, check its expiry, and understand why decoding is not verifying.
- How to Check HTTP Redirects Trace a URL through every hop to its destination, and tell a permanent redirect from a temporary one.
- How to Format JSON Turn minified or broken JSON into something readable, and fix it when it will not parse.
Last reviewed .