415 Unsupported Media Type means: The server refuses the request because the payload's media type (Content-Type) is unsupported. The endpoint might accept JSON but the client sent XML, form data, or plain text — or forgot the header entirely. Client-error 4xx codes mean the request itself is the problem: malformed syntax, missing credentials, forbidden access, a nonexistent resource or a violated precondition. The server is telling the client what to change; retrying the identical request without a fix will reproduce the same error. In practice you will meet 415 when missing or wrong content-type on a post/put (e.g. text/plain for json); sending multipart/form-data to an endpoint that only parses application/json; an unsupported charset or encoding declared in content-type. On the client side, set Content-Type to exactly what the API documents (usually application/json) and ensure the body actually matches that format. On the server side, return 415 with the accepted types listed (Accept-Post or body details); do not silently guess the format — that creates security and parsing ambiguity.
When 415 happens
- Missing or wrong Content-Type on a POST/PUT (e.g. text/plain for JSON)
- Sending multipart/form-data to an endpoint that only parses application/json
- An unsupported charset or encoding declared in Content-Type
How to fix it
On the client
Set Content-Type to exactly what the API documents (usually application/json) and ensure the body actually matches that format.
On the server
Return 415 with the accepted types listed (Accept-Post or body details); do not silently guess the format — that creates security and parsing ambiguity.
Should you retry?
Not retryable as-is: change the request (credentials, payload, URL) first.
Debugging steps
When 415 appears unexpectedly, start by capturing the full exchange: 'curl -i' or the browser DevTools Network tab shows the exact status line and response headers, which often carry the real explanation. Read the error body first — well-designed APIs name the offending field or missing credential. Then diff your actual request, headers included, against the documented contract. For this code specifically, check whether the most common trigger applies to your situation: missing or wrong content-type on a post/put (e.g. text/plain for json). Compare your exchange against the raw HTTP example above. If you operate the server, correlate the timestamp with application and proxy logs using the request id; if you are the client, verify the request shape against the API documentation before changing anything or retrying.
Notes & gotchas
Servers route parsers by Content-Type, so a perfectly valid JSON body declared as text/plain can still earn 415; the header must describe the payload honestly.
Examples
HTTP/1.1 415 Unsupported Media Type
Accept-Post: application/json
Content-Type: application/json
Content-Length: 126
{
"error": "unsupported_media_type",
"message": "Missing or wrong Content-Type on a POST/PUT (e.g. text/plain for JSON)"
} curl -i -X POST -H "Content-Type: text/plain" -d '{"a":1}' https://api.example.com/v1/resource # wrong media type reproduces 415 const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 415) {
const problem = await res.json(); // read field-level details
// fix the request (credentials, payload, URL) — identical retries keep failing
throw new RequestError(problem);
} import requests
res = requests.get("https://api.example.com/v1/resource", timeout=10)
if res.status_code == 415:
problem = res.json() # field-level error details
# correct the request before retrying — identical retries keep failing
raise RequestProblem(problem) Frequently asked questions
415 vs 400: my JSON body is valid, why 415?
415 is about the declared media type, not the body's validity. A perfect JSON body sent as text/plain can still earn 415 because the server routes parsers by Content-Type.
What is Accept-Post?
A response header (RFC 8594) listing media types the endpoint accepts for POST; pair it with 415 so clients can self-correct.
Are 4xx errors always the client's fault?
By contract yes — the server asserts the request must change. In practice servers sometimes misuse 4xx for their own problems (e.g. 400 for internal validation bugs), so read the error body before blaming your client code.
Should I retry 4xx responses automatically?
Generally no: the server says the request must change. Exceptions are 408 (fresh connection), 425 (after handshake) and 429 (after Retry-After). Blind retries of 400/401/403/404 just burn quota.
Try the JSON Validator
Check JSON syntax and locate errors by line and column.