When a request fails in the browser but you can't tell why, the fastest way to dig in is to replay it outside the page. Every major browser can copy any network request as a curl command with the same method, URL, headers, cookies and body. You can then run it, edit it one piece at a time and attach it to a bug report.
Copy a request
- Open DevTools (F12, or Cmd+Option+I on macOS) and switch to the Network panel.
- Reload the page or trigger the action so the request appears.
- Right-click the request:
- Chrome and Edge: Copy > Copy as cURL (bash), or (cmd) on Windows.
- Firefox: Copy Value > Copy as cURL (POSIX or Windows).
- Safari: Copy as cURL (enable the Develop menu in Settings > Advanced first).
Filtering the Network panel by Fetch/XHR hides images and scripts so the API call is easier to find.
What you get
A typical copied command looks like this:
curl 'https://api.example.com/v1/orders?status=open' \
-H 'accept: application/json' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'authorization: Bearer eyJhbGciOi...' \
-H 'cookie: session=abc123; theme=dark' \
-H 'origin: https://app.example.com' \
-H 'referer: https://app.example.com/orders' \
-H 'sec-ch-ua: "Chromium";v="141"' \
-H 'sec-fetch-mode: cors' \
-H 'user-agent: Mozilla/5.0 ...' \
--data-raw '{"page":2}'
--data-raw sends the body as-is and makes curl use POST unless -X says otherwise.
Trim it down
Most headers are added by the browser and don't matter to the server. Removing them makes the command readable and shows which ones do matter. Usually safe to delete first:
sec-ch-ua*andsec-fetch-*: client hints and fetch metadata.accept-language,accept-encoding,priority,cache-control,pragma.user-agent, unless the server behaves differently per browser.refererandorigin, unless the server checks them (CORS and CSRF protection often do).
Keep authorization, cookie, content-type and any custom x- headers until you've confirmed they aren't needed. Then remove one header at a time: when the response changes, you've found what the server depends on.
Useful curl options while debugging
curl -i URL # include response headers
curl -v URL # show the full request and response, including TLS
curl -L URL # follow redirects
curl -sS URL # no progress bar, but still show errors
curl -o /dev/null -w '%{http_code} %{time_total}s\n' -s URL # status and timing only
curl --compressed URL # ask for gzip/br and decompress
Pipe JSON responses through jq . to format them, or paste them into a formatter.
Don't leak credentials
A copied command contains everything needed to act as the logged-in user: session cookies, bearer tokens, sometimes CSRF tokens. Before pasting it into a ticket, chat or AI assistant:
- Replace
cookieandauthorizationvalues with placeholders like<SESSION>and<TOKEN>. - Check the URL and body for API keys or personal data.
- If a real token was shared, log out or revoke it so it stops working.
From curl to code
Once the request works in the terminal, it often needs to become code: a reproduction script, a test or a new API client. The fetch equivalent of the trimmed command above is:
const response = await fetch("https://api.example.com/v1/orders?status=open", {
method: "POST",
headers: {
"accept": "application/json",
"authorization": "Bearer <TOKEN>",
"content-type": "application/json",
},
body: JSON.stringify({ page: 2 }),
});
const data = await response.json();
A few curl behaviors don't carry over to fetch:
-k/--insecure: fetch can't skip certificate checks.- Cookies in browsers: a page can't set the
Cookieheader in fetch; usecredentials: "include"and let the browser send its cookies. Node.js can set the header. - Redirects: fetch follows them by default; curl only does with
-L. - Timeouts:
--max-timebecomessignal: AbortSignal.timeout(ms).
For a detailed look at sending a JSON body, see the curl POST JSON example. If the replayed request comes back with a 3xx status, the redirect guide explains which ones change the method.