aspnet-api-versioning: UnsupportedApiVersion error when giving some different content type
We are using 4.1.1 version of APiVersioning and 3.1 version of Asp.NetCore I have a controller with an action which accepts only Content-Type “application/merge-patch+json”
[HttpPatch("{id}")]
[Consumes("application/merge-patch+json")]
public async Task<Object> CreateObjectAsync(
..
)
{
..
..
}
So while quering for the given api with content type “application/merge-patch+json”… It works fine but quering for some other valid content type for example “application/json” gives 400 bad request and following output:
{
"error": {
"code": "UnsupportedApiVersion",
"message": "The HTTP resource that matches the request URI 'https://bb-df-wus2-1.farmbeats-dogfood.azure.net/farmers/pra88888m?api-version=2021-03-31-preview' does not support the API version '2021-03-31-preview'."
}
}
and on using APiVersioning version as “5.0.0” I got the same response with different status code. Can you please help me with this?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16
@commonsensesoftware I verified its working without versioning. It gives proper error 415 UnSupportedMediaType. You can verify it once on some sample controllers.
Yes, We want “application/merge-patch+json” according to some guidelines. I’ll reconfirm on Patch + application/json thing. But We want to support “application/merge-patch+json” and we might need any other content type also for that matter for any scenario. We shall try to fix this to get unblocked early.
This provides a little more about the action, but it doesn’t provide any information about the controller or application setup. I still have a number of questions.
PATCH
withapplication/merge-patch+json
works, but not withapplication/json
. a. It appears you are trying implement RFC 7386 b. You’ve only mappedapplication/merge-patch+json
with the ConsumesAttribute, so I would expectapplication/json
to fail c. I would expect HTTP 415 (Unsupported Media Type) ifapplication/json
is in theContent-Type
header for this action d. Like media types, the API version is a constraint used to filter down candidates. It’s possible, things are short-circuit before other failures have a chance to execute. This could mean no candidates were found before HTTP 406 or 415 was evaluated.I’m not 100% sure what that means. API Versioning has very few errors it throws. It will, however, return client errors - without exception - for invalid requests. There are ways to change the error response; for example, a different status code, message, or payload. It’s unclear if that’s what you mean by
"...error out properly."
I want to make sure I understand your scenario before I send you down that path.