2

I tried to create an item using Item Service in Sitecore.Services.Client. But when I try to create an item am facing

500 Internal server not found

error during item creation.

Below I attached the code sample that I used.

                var xhr = new XMLHttpRequest();
                xhr.open("POST", "http://sitecore91.sc/sitecore/api/ssc/item/sitecore/content/Home ");
                xhr.setRequestHeader("Content-Type", "application/json");
                xhr.onreadystatechange = function () {
                    if (this.readyState == 4) {
                        alert('Status: ' + this.status + '\nHeaders: ' + JSON.stringify(this.getAllResponseHeaders()) + '\nBody: ' + this.responseText);
                    }
                };
                xhr.send("{\"ItemName\": \"Home\",\"TemplateID\": \"76036f5e-cbce-46d1-af0a-4143f9b557aa\"}");
7
  • Can you hit the endpoint with postman? Are there any entries in the log files that might be related? My off the cuff guess is that the Item API is not enabled.
    – Gravypower
    Feb 4, 2019 at 9:21
  • 1
    i checked with postman ,nothing get's returned. where i need to enable item API?
    – Rajasekar
    Feb 4, 2019 at 9:31
  • Could not find any recent docs, have a look at sdn.sitecore.net/upload/sdn5/modules/… see Security on page 12. Not sure if this is still current sorry
    – Gravypower
    Feb 4, 2019 at 9:55
  • 1
    Not working. I Changed and checked. but this is used when we use item web api but i'm using sitecore.services.client .
    – Rajasekar
    Feb 4, 2019 at 10:59
  • 1
    Hi, GTHvidson it's permission related issue
    – Rajasekar
    Feb 5, 2019 at 14:01

2 Answers 2

2

We need to provide access rights to sitecore\ServicesAPI user. I was fixed that error by setting admin rights to

sitecore\ServicesAPI

user in usermanger.

2
  • This solution should be applied with extreme care. Anonymous requests run under the security context of this account by default so you are effectively giving admin access to anonymous users.
    – Jeroen
    May 15, 2019 at 15:13
  • 1
    yes. That's true
    – Rajasekar
    May 16, 2019 at 9:20
0

According to the ItemService documentation, the item path needs to be URL encoded, and your code does not do this.

Where your code does the following:

xhr.open("POST", "http://sitecore91.sc/sitecore/api/ssc/item/sitecore/content/Home ");

The proper way should be this:

xhr.open("POST", "http://sitecore91.sc/sitecore/api/ssc/item/sitecore%2Fcontent%2Fhome");

3
  • 1
    I tried this also. but it's not working for me. still am facing 500 internal server error.
    – Rajasekar
    Feb 5, 2019 at 6:56
  • 1
    <setting name="Sitecore.Services.SecurityPolicy" value="Sitecore.Services.Infrastructure.Web.Http.Security.ServicesOnPolicy, Sitecore.Services.Infrastructure" /> i have changed the security policy & anonymous user to true also.
    – Rajasekar
    Feb 5, 2019 at 6:59
  • 1
    note: Get Request for item Getting is working
    – Rajasekar
    Feb 5, 2019 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.