api config_error ai_generated true

400 Bad Request: API version header 'X-API-Version' is required and must be a valid semver

ID: api/rest-api-version-mismatch-header

Also available as: JSON · Markdown · 中文
95%Fix Rate
86%Confidence
1Evidence
2024-05-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
REST API best practices 2023+ active
Spring Boot 3.x active
FastAPI 0.100+ active
Express.js 4.x active

Root Cause

The client did not include the required 'X-API-Version' header in the request, or the value does not conform to semantic versioning (e.g., '2.0' instead of '2.0.0').

generic

中文

客户端未在请求中包含必需的 'X-API-Version' 标头,或者该值不符合语义化版本控制(例如,'2.0' 而非 '2.0.0')。

Official Documentation

https://semver.org/

Workarounds

  1. 95% success Add the 'X-API-Version' header with a valid semver value. Example in cURL: curl -H 'X-API-Version: 2.0.0' https://api.example.com/resource
    Add the 'X-API-Version' header with a valid semver value. Example in cURL:
    curl -H 'X-API-Version: 2.0.0' https://api.example.com/resource
  2. 90% success Check the API documentation for the exact version string required (e.g., '1.0.0', '2.1.3').
    Check the API documentation for the exact version string required (e.g., '1.0.0', '2.1.3').
  3. 95% success If using an HTTP client library, set default headers. Example in Python requests: headers = {'X-API-Version': '2.0.0'} response = requests.get('https://api.example.com/resource', headers=headers)
    If using an HTTP client library, set default headers. Example in Python requests:
    headers = {'X-API-Version': '2.0.0'}
    response = requests.get('https://api.example.com/resource', headers=headers)

中文步骤

  1. Add the 'X-API-Version' header with a valid semver value. Example in cURL:
    curl -H 'X-API-Version: 2.0.0' https://api.example.com/resource
  2. Check the API documentation for the exact version string required (e.g., '1.0.0', '2.1.3').
  3. If using an HTTP client library, set default headers. Example in Python requests:
    headers = {'X-API-Version': '2.0.0'}
    response = requests.get('https://api.example.com/resource', headers=headers)

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The server strictly requires the header; omitting it results in a 400 error.

  2. 70% fail

    The server expects a full semver string (e.g., '2.0.0'); partial versions are rejected.

  3. 95% fail

    The server specifically looks for 'X-API-Version'; other headers are ignored.