415 Unsupported Media Type means the server rejected the request because the body's format (Content-Type) is not one it supports. For example, sending XML or text/plain to an endpoint that only accepts JSON triggers it.
Where 406 Not Acceptable is about failed negotiation of the response (what the server produces), 415 is about the format of the request body (what the client sends).
POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: text/xml
<user><name>Kim</name></user>HTTP/1.1 415 Unsupported Media Type
Accept-Post: application/json
Content-Type: application/json
{"error":"unsupported_media_type","expected":"application/json"}app.post('/api/users', (req, res) => {
if (!req.is('application/json')) {
return res.status(415)
.set('Accept-Post', 'application/json')
.json({ error: 'unsupported_media_type' });
}
// ...
});curl -X POST https://api.example.com/api/users \
-H 'Content-Type: application/json' \
-d '{"name":"Kim"}'