Common Causes

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:

  1. Check the response body — the server usually includes an error message
  2. Validate your JSON with our JSON Formatter
  3. Verify Content-Type matches your body format
  4. Check API docs for required fields and their types

400 vs 422 vs 401

CodeMeaning
400 Bad RequestRequest syntax is malformed — server can't parse it
401 UnauthorizedRequest is valid but authentication is required/failed
422 Unprocessable EntityRequest is valid syntax but fails validation (e.g. email format wrong)