Archive
REST API, PATCH request error, Postman – Valid content types for this method are: application/json-patch+json
I was trying to use the Azure DevOps REST APIs to get some details of VSO WorkItems by using Postman tool. Doing GET-Request was not a problem and it returned the expected JSON response body with all attributes and details.
But when I tried to update the same VSO WorkItem by using POST request it resulted in below error:
{
“$id”: “1”,
“innerException”: null,
“message”: “The request indicated a Content-Type of \”application/json\” for method type \”PATCH\” which is not supported. Valid content types for this method are: application/json-patch+json.“,
“typeName”: “Microsoft.VisualStudio.Services.WebApi.VssRequestContentTypeNotSupportedException, Microsoft.VisualStudio.Services.WebApi”,
“typeKey”: “VssRequestContentTypeNotSupportedException“,
“errorCode”: 0,
“eventId”: 3000
}
Solution:
As the above error mentions to use “application/json-patch+json” as the Content Type, so the same has to be added under the Headers tab as Key Value, like:
KEY: Content-Type
VALUE: application/json-patch+json
If you observe similar error while working with PowerShell, you’ve to pass the same value with ContentType parameter in the Invoke-RestMethod command:
Invoke-RestMethod -Method Post -Uri $theUri -Headers $theHeader -ContentType “application/json-patch+json” -Body $theBody