406

Not Acceptable

4xx Client Error

ELI5

I can't give you the data in the format you want. I have the data, but not in XML/JSON/etc. that you asked for.

Server perspective

Use 406 when the client's proactive negotiation constraints leave no representation you are willing to serve.

When to use

  • Return 406 when Accept, Accept-Language, or Accept-Encoding excludes every available representation
  • Use it when you do not want to fall back to a default representation
  • Client requests unsupported response format
  • Accept header specifies unavailable content types
  • Language negotiation fails
  • Encoding negotiation fails

How to respond

  • List the available representations or supported values when that helps the client recover
  • Keep 406 distinct from 415, which is about the request payload format

Headers to consider

  • No status-specific header is required; still send normal HTTP metadata such as Content-Type, caching, or tracing headers when they help the client.

Response body

  • Include available representation formats when that helps the client adjust Accept headers.

Server-side pitfalls

  • Do not use 406 for unsupported request Content-Type
  • Do not send 406 if serving a documented default representation is acceptable for your API
  • Request media type unsupported (use 415 Unsupported Media Type)
  • Resource doesn't exist (use 404 Not Found)
  • Bad request format (use 400 Bad Request)

Examples

Unsupported response format

Request:GET https://api.example.test/api/data # Headers Accept: application/xml
Response:406 Not Acceptable # Headers Content-Type: application/json # Body { "available": [ "application/json" ] }

API only supports JSON responses, not XML

References

Related Status Codes