A request works in one place and fails in another: how to debug it

"It works on my machine" has an API version: the request passes in the app and fails in CI, or works in curl and returns 401 in the API client, or worked yesterday. Almost every case comes down to one thing. The request that went out isn't the one you think went out. So the fastest path is to see the actual request on both sides and compare.

1. Read the whole response

Before changing anything, read what the server said. A 401 with WWW-Authenticate: Bearer error="invalid_token" is a different problem from a 403, and both are different from a 400 that names a missing field. Many APIs put a reason in the body or a request ID in a header; with a request ID, the server's logs tell you the rest.

StatusUsually means
400 / 422the body or a parameter isn't what the server expects
401no credential, a wrong one, or an expired one
403the credential is fine; this identity isn't allowed
404wrong base URL or path, or the object doesn't exist in this environment
415wrong or missing Content-Type

2. Look for unresolved variables

The same request run against a different environment is a different request. If {{token}} exists in your Local environment but not in Staging, it's sent literally, or the request isn't sent at all.

  • In the app, unresolved {{variables}} are highlighted in the URL bar and fields.
  • In the CLI, a request with a missing variable errors and the JSON report lists them:
Terminal
requestarium run-collection "Users API" --env Staging --out report.json
jq '.results[] | select(.missingVariables | length > 0) | {path, missingVariables}' report.json

In CI, a secret that wasn't passed to the job looks exactly like this. Check --env-var names and that the job actually exposes the secret.

3. Print what was really sent

Variables, inherited collection and folder auth, and scripts all change the request between what you see and what goes out. Print the result at the end of the pre-request script:

JavaScript
console.log(pm.request.method, pm.variables.replaceIn(pm.request.url.toString()));
console.log('Authorization present:', !!pm.request.headers.get('Authorization'));

The output is in the Console of the response pane. Avoid logging full secrets; even masked, they don't belong in logs.

In the CLI, --verbose prints request and response headers, script console output and, for run-collection, each response body, with secrets masked:

Terminal
requestarium run "Get current user" --collection "Users API" --env Staging --verbose

4. Compare with a known-good call

If curl works and the client doesn't (or the other way round), make them comparable. Open the request's Code panel and pick cURL: you get a command built from the same URL, headers and body. Run it in your terminal and diff it against the curl that works. Usual differences: a header the curl has and the request doesn't (Accept, User-Agent, a cookie), a trailing slash, or http vs https.

5. Then the network

If the request is identical and the result isn't, it's where the request comes from:

When it fails only sometimes

That's a flaky test, and it deserves its own approach: retries for the right status codes, a pass rate, and run history to see the pattern. See How to deal with flaky API tests.