sitecoresitecore7.2

Attempting to use the Sitecore Web API to create an object causes BadRequestException


I've written some code to call the Sitecore Web API and create folders and other objects, using HTTP POST requests. These calls used to work for Sitecore v6, but now that I'm running them against Sitecore v7.2, they no longer work. GET requests still work fine.

An example of the POST that I'm doing is as follows:

URL: http://sitecore.testsite/-/item/v1/sitecore/Content/Home/Abc?template=Common%2fFolder&name=Def&sc_database=master

Headers:

Here is the exact error description from the log:

ERROR [Item Web API] The specified Content-Type is not supported. Exception: Sitecore.ItemWebApi.BadRequestException Message: The specified Content-Type is not supported. Source: Sitecore.ItemWebApi
at Sitecore.ItemWebApi.Pipelines.Request.ResolveAction.ExecuteCreateRequest(RequestArgs args) at (Object , Object[] ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.ItemWebApi.Pipelines.HttpRequest.LaunchRequest.Process(HttpRequestArgs arguments)

Let me know if you'd like some C# code, or a screenshot of Postman.


Solution

  • I managed to figure this out by decompiling Sitecore.ItemWebApi.dll:

    1. Set the Content-Type to application/x-www-form-urlencoded
    2. The body of the request must contain fieldId=
      (I don't know what fieldId should be set to, but using blank seems to work fine)