HTTP

Status Code

415 Unsupported Media Type

The server doesn't support the media type of the request. Learn about Content-Type headers and format requirements.

4 min read beginner Try in Playground

What is a 415 Error?

TL;DR: Server doesn’t support the Content-Type format you sent. Check your Content-Type header and send data in a supported format.

A 415 Unsupported Media Type status code means the server doesn’t understand or support the format of data you sent. Think of it like trying to play a Blu-ray disc in an old DVD player—the player works fine, but it doesn’t know how to handle that specific format.

The server received your request successfully, but the Content-Type header indicates a format that the server can’t process.

When Does This Happen?

You’ll see a 415 error in these common situations:

1. Wrong Content-Type Header

You send:     JSON data
But header:   Content-Type: text/plain
Server expects: application/json
Result:       415 Unsupported Media Type

2. Unsupported File Format

You upload:   .webp image file
Server accepts: Only .jpg, .png, .gif
Result:       415 Unsupported Media Type

3. Missing Content-Type

You send:     POST request with data
But missing:  Content-Type header entirely
Server needs: Explicit content type
Result:       415 Unsupported Media Type

4. API Format Mismatch

You send:     XML data
API expects:  Only JSON format
Result:       415 Unsupported Media Type

5. Incorrect Encoding

You send:     application/json; charset=utf-16
Server needs: application/json; charset=utf-8
Result:       415 Unsupported Media Type

Example Response

When the media type isn’t supported, the server responds like this:

HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json
Accept: application/json, application/xml
Content-Length: 189

{
  "error": "Unsupported media type",
  "message": "Content-Type 'text/plain' is not supported",
  "supported_types": ["application/json", "application/xml"],
  "received_type": "text/plain"
}
```text

Key parts of this response:

- **415 Unsupported Media Type** - The status code and reason
- **Accept header** - Lists the media types the server supports
- **Content-Type** - Format of the error response
- **Body** - Details about what was received vs. what's supported

## Real-World Examples

**Example 1: JSON API with Wrong Content-Type**

```http
POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: text/plain
Content-Length: 45

{"name": "John Doe", "email": "john@example.com"}

Response:

HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json
Accept: application/json

{
  "error": "Unsupported media type",
  "message": "API only accepts JSON data",
  "expected": "application/json",
  "received": "text/plain",
  "fix": "Set Content-Type header to 'application/json'"
}
```text

**Example 2: File Upload with Unsupported Format**

```http
POST /upload/avatar HTTP/1.1
Host: fileserver.com
Content-Type: image/webp
Content-Length: 15420

[WebP image data...]

Response:

HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json
Accept: image/jpeg, image/png, image/gif

{
  "error": "Unsupported image format",
  "message": "WebP images are not supported",
  "supported_formats": ["JPEG", "PNG", "GIF"],
  "received_format": "WebP",
  "convert_suggestion": "Please convert to JPEG or PNG format"
}
```text

## How to Fix 415 Errors

**As a Developer:**

- Check the `Accept` header in the response for supported types
- Set the correct `Content-Type` header in your requests
- Verify your data format matches the Content-Type
- Convert data to a supported format if needed

**As an API Consumer:**

- Read the API documentation for supported formats
- Use the correct MIME type for your data
- Include proper charset encoding when needed
- Test with different content types if unsure

## 415 vs Other Similar Codes

| Code    | Meaning                | What's Different                           |
| ------- | ---------------------- | ------------------------------------------ |
| **415** | Unsupported media type | Server doesn't support the data format     |
| **400** | Bad request            | Request syntax or structure is wrong       |
| **406** | Not acceptable         | Server can't produce the format you want   |
| **422** | Unprocessable entity   | Format is correct but data is invalid      |
| **413** | Payload too large      | Data size exceeds limits, not format issue |

## Common Content-Type Issues

**❌ Missing Content-Type header**

```javascript
// This might cause 415 error
fetch('/api/users', {
  method: 'POST',
  body: JSON.stringify({ name: 'John' })
  // Missing Content-Type header
})

✅ Correct Content-Type header

// Proper JSON request
fetch('/api/users', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ name: 'John' })
})
```javascript

**❌ Wrong Content-Type for form data**

```javascript
// This is wrong for form uploads
const formData = new FormData()
formData.append('file', file)

fetch('/upload', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json' // Wrong!
  },
  body: formData
})

✅ Let browser set Content-Type for FormData

// Browser automatically sets multipart/form-data
const formData = new FormData()
formData.append('file', file)

fetch('/upload', {
  method: 'POST',
  // Don't set Content-Type - browser handles it
  body: formData
})
```text

## Common Media Types

**JSON Data:**

```http
Content-Type: application/json
```text

**Form Data:**

```http
Content-Type: application/x-www-form-urlencoded
```text

**File Uploads:**

```http
Content-Type: multipart/form-data
```text

**XML Data:**

```http
Content-Type: application/xml
```text

**Plain Text:**

```http
Content-Type: text/plain
```text

**Images:**

```http
Content-Type: image/jpeg
Content-Type: image/png
Content-Type: image/gif
```javascript

## Server-Side Handling

**Express.js example:**

```javascript
app.use(express.json()) // Handles application/json
app.use(express.urlencoded({ extended: true })) // Handles form data

app.post('/api/users', (req, res) => {
  const contentType = req.get('Content-Type')

  if (!contentType || !contentType.includes('application/json')) {
    return res.status(415).json({
      error: 'Unsupported media type',
      message: 'This endpoint only accepts JSON',
      expected: 'application/json',
      received: contentType || 'none'
    })
  }

  // Process JSON data...
})

Try It Yourself

Visit our request builder and test different content types:

  1. Set method to POST
  2. Set path to /api/users
  3. Set Content-Type to text/plain
  4. Add JSON data in the body
  5. Watch for the 415 response

Frequently Asked Questions

What does 415 Unsupported Media Type mean?

A 415 error means the server cannot process the Content-Type of your request body. You are sending data in a format the server does not support, like sending XML when it expects JSON.

How do I fix a 415 error?

Check the Content-Type header in your request. Change it to match what the server expects, usually application/json for APIs. Ensure your request body format matches the Content-Type.

What is the difference between 415 and 406?

415 means the server cannot process the format you sent (request body). 406 means the server cannot return content in the format you accept (response). 415 is input; 406 is output.

What Content-Type should I use for JSON?

Use application/json for JSON data. Common mistakes include using text/plain, text/json, or forgetting the header entirely. Always set Content-Type explicitly for POST and PUT requests.

Keep Learning