Common Causes
- Malformed JSON body — missing comma, unclosed bracket, trailing comma
- Invalid query parameters — wrong type, out-of-range value, missing required param
- Wrong Content-Type header — sending JSON but declaring
multipart/form-data - Oversized request — body exceeds server's size limit
- Invalid URL — special characters not URL-encoded
- Missing required fields — API expects a field that wasn't included
Debugging 400 Errors
// Check your request in fetch
fetch('/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }, // ← required for JSON
body: JSON.stringify({ name: 'Alice', email: 'alice@example.com' })
})
.then(async res => {
if (!res.ok) {
const error = await res.json();
console.error('400 Error:', error); // check the response body for details
}
});
Steps to diagnose:
- Check the response body — the server usually includes an error message
- Validate your JSON with our JSON Formatter
- Verify Content-Type matches your body format
- Check API docs for required fields and their types
400 vs 422 vs 401
| Code | Meaning |
|---|---|
| 400 Bad Request | Request syntax is malformed — server can't parse it |
| 401 Unauthorized | Request is valid but authentication is required/failed |
| 422 Unprocessable Entity | Request is valid syntax but fails validation (e.g. email format wrong) |