406 api version_error ai_generated true

406 Not Acceptable: API version specified in Accept header is not supported

ID: api/rest-api-version-header-missing-accept

Also available as: JSON · Markdown · 中文
90%Fix Rate
89%Confidence
1Evidence
2023-09-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
REST API versioning via Accept header active
ASP.NET Core 8.0 active
Spring MVC 6.1 active
Express.js 4.18 active

Root Cause

Client sent an Accept header with a media type that includes an API version (e.g., application/vnd.myapp.v2+json) that the server does not recognize or does not serve.

generic

中文

客户端发送的 Accept 头包含的媒体类型中指定了服务器无法识别或不提供的 API 版本(例如 application/vnd.myapp.v2+json)。

Official Documentation

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406

Workarounds

  1. 95% success Verify the exact version string the server supports by checking the API documentation or querying a version discovery endpoint. Use the correct media type, e.g., application/vnd.myapp.v1+json for version 1.
    Verify the exact version string the server supports by checking the API documentation or querying a version discovery endpoint. Use the correct media type, e.g., application/vnd.myapp.v1+json for version 1.
  2. 85% success If the API uses a URL-based versioning scheme (e.g., /api/v1/), switch to that instead of Accept header versioning. Many APIs support both methods.
    If the API uses a URL-based versioning scheme (e.g., /api/v1/), switch to that instead of Accept header versioning. Many APIs support both methods.

中文步骤

  1. 通过查看 API 文档或查询版本发现端点,验证服务器支持的确切版本字符串。使用正确的媒体类型,例如 v1 版本使用 application/vnd.myapp.v1+json。
  2. 如果 API 使用基于 URL 的版本控制方案(例如 /api/v1/),则切换为使用该方案而不是 Accept 头版本控制。许多 API 同时支持这两种方法。

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Without the Accept header, the server may default to the latest version or return a generic response, but this defeats version negotiation and may cause unexpected behavior.

  2. 80% fail

    The server may interpret application/json as the latest version, but if the client specifically needs an older version, this will not work and may break backward compatibility.