1

enter image description hereI modified to allow anonymous setting to true in Sitecore.Services.Client.config

var xhrp = new XMLHttpRequest();
        xhrp.open("POST", "http://sitecorenew.sc/sitecore/api/ssc/item/sitecore%2Fcontent%2Fhome ");
        xhrp.setRequestHeader("Content-Type", "application/json");
        xhrp.onreadystatechange = function () {
            if (this.readyState == 4) {
                alert('Status: ' + this.status + '\nHeaders: ' + JSON.stringify(this.getAllResponseHeaders()) + '\nBody: ' + this.responseText);
            }
        };
        xhrp.send("{ \n    \"ItemName\": \"Home\", \n    \"TemplateID\": \"76036f5e-cbce-46d1-af0a-4143f9b557aa\", \n    \"Title\": \"Sitecore\", \n    \"Text\": \"\\r\\n\\t\\t\u003Cp\u003EWelcome to Sitecore\u003C/p\u003E\\r\\n\" \n}");
1

You have to generate a authentication cookie and send that along with the request. FYI ... This must be called via HTTPS

Get the cookie like so:

var xhr = new XMLHttpRequest();
xhr.open("POST", "https://sitecorenew.sc/sitecore/api/ssc/auth/login");
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("{ \n \"domain\": \"sitecore\", \n \"username\": \"admin\", \n \"password\": \"b\" \n}");

Taken from: https://doc.sitecore.net/sitecore_experience_platform/90/developing/developing_with_sitecore/sitecoreservicesclient/the_restful_api_for_the_itemservice

  • i try this put still showing the same response 405 method not allowed – PC007 Jun 20 '18 at 11:38
  • It seems that maybe you have might have IIS mis-configured. Make sure you have your SSL setup correctly. – Kevin Jun 20 '18 at 13:51
  • login response with ok 200 but create new response with 403 forbidden – PC007 Jun 21 '18 at 14:16
  • Can you update your code to show what you've changed. After you get the cookie, you must pass it into your Create Item request. Your previous example doesn't show that. – Kevin Jun 22 '18 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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