3

We're in the process of integrating with a product management tool to automate the process of item/product creation within our system. I know that Sitecore has the ability to pass back the objects directly through URL reference, but is there a way to pass a JSON object, or something like that, which would be able to include a reference to a template maybe, and a location/parent node to save it to, and create a new instance of the item, and save it appropriately?

We do something like that now in our manual process, which can create an item based on an excel spreadsheet, but that was entirely home-grown, and programmatically creates the item (or version if it's already there) and that get's saved back where it belongs.

Is there anything out of the box that sitecore provides that would perform that object creation?

  • Hey Jon, have you heard of Sitecore PowerShell Extensions? It's not an out of the box solution but does offer the ability to build your own API. – Michael West Feb 16 '17 at 2:00
6

Item Web API

For Sitecore versions from 6+ till 8 you should use the Sitecore Item Web API.

Documentation is available here: link

Creating an Item from a Template

To create an item called MyItem that is based on the Sample Item template in the master database, use a URL in the following format:

http:///- /item/v1/sitecore/Content/Home?name=MyItem&template=Sample/Sample Item&sc_database=master

Sitecore Services Client

For newer Sitecore versions (8+) the Sitecore.Services.Client must be used:

Please, check this document by Sitecore (p.3.4.5 Create an Item): link

You use this method to create a new Sitecore item.

Verb: POST

URL: /item/{path}?database&language

  • A couple of comments... I tried this first piece (same as below... if I had more points for the board, I'd upvote both) but all I was able to do with the suggested urls (with querystring parameters) was get a returned piece of json, which seemed to be the home node. So it seemed like I was getting the correct location and format, but seemed like I was hitting a get() and not an insert... that all being said, we're using 7.2 now, but redoing the site in 8.2 later in the year... looks like a different implementation would be needed anyway... is there any way to use the newer way on 7.2 – Jon Feb 17 '17 at 5:18
  • @Jon the new method is available from 7.5 onwards – Andrey Bobrov Feb 17 '17 at 7:15
3

You can also use the Sitecore ItemService API to do this like so:

var xhr = new XMLHttpRequest();
xhr.open("POST", "http://<your server>/sitecore/api/ssc/item/sitecore%2Fcontent%2Fhome ");
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    \"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}");

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

2

You can use sitecore Sitecore Item Web API to create an item.

http://[host_name]/-/item/v1/sitecore/Content/Home?name=MyItem&template=Sample/Sample Item&sc_database=master

Also make sure you have these settings in your Sitecore.ItemWebApi.config

itemwebapi.mode="StandardSecurity"
itemwebapi.allowanonymousaccess="false"/>

For more info https://sdn.sitecore.net/upload/sdn5/modules/sitecore%20item%20web%20api/sitecore_item_web_api_developer_guide_sc65-66-usletter.pdf

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.