error code 415

HTTP Status Code 415 = “Unsupported Media Type”

The server refuses to process the request because the request body format or Content-Type is not supported.

Common causes

  • Wrong Content-Type header
  • Sending JSON as plain text
  • Unsupported file upload type
  • Invalid multipart/form-data request
  • API expects XML but receives JSON
  • Corrupted request payload Example

Wrong request

http id=”x4m9qa”
POST /api/users HTTP/1.1
Content-Type: text/plain

But the API expects:

http id=”t7k2we”
Content-Type: application/json

Response

http id=”n3p8zd”
HTTP/1.1 415 Unsupported Media Type

Fixes

1. Use correct Content-Type

JSON API

http id=”w8q1rc”
Content-Type: application/json

Form upload

http id=”u5m4yn”
Content-Type: multipart/form-data

2. Axios example

js id=”k9v2xe”
axios.post(‘/api/users’, data, {
headers: {
‘Content-Type’: ‘application/json’
}
});

3. Fetch API

js id=”b7p3qd”
fetch(‘/api/users’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’
},
body: JSON.stringify(data)
});

4. PHP cURL

php id=”g2m8ra”
curl_setopt($ch, CURLOPT_HTTPHEADER, [
‘Content-Type: application/json’
]);

File upload example

Allowed

  • .jpg
  • .png
  • .pdf

Blocked

  • .exe
  • Unsupported MIME type

May trigger 415.

Laravel example

php id=”y6w1kc”
$request->validate([
‘image’ => ‘mimes:jpg,png,jpeg’
]);

Difference between 400 and 415

| Code | Meaning |
| — | |
| 400 | Invalid request syntax/data |
| 415 | Unsupported content format |

Common media types

| Type | Content-Type |
| – | |
| JSON | application/json |
| HTML | text/html |
| XML | application/xml |
| Form Data | multipart/form-data |
| Plain Text | text/plain |

Related HTTP status codes

| Code | Meaning |
| — | – |
| 400 | Bad Request |
| 401 | Unauthorized |
| 413 | Payload Too Large |
| 415 | Unsupported Media Type |
| 422 | Unprocessable Entity |
| 500 | Internal Server Error |