I'm using the ItemService API in Javascript to login to sitecore and dynamically create items (documentation i'm using)

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}");

When items are created, i need to publish them but i can't find any informations in the doc about that. Is it possible to do that right after the item is created?

Thanks in advance for your help

  • I don't believe that you can publish via the Sitecore API. It seems pretty limited.
    – Kevin
    Jun 27, 2018 at 14:19
  • @Kevin: Thank you for answering. I'm kind of suprised that an API gives us the possibility to create items but not publish them... Do you happen to know any other solutions to achieve such a thing ?
    – Slrg
    Jun 27, 2018 at 14:26

2 Answers 2


You can use the PublishManager class to handle publishing of items in Sitecore.

PublishManager.PublishItem(Item item, Database[] targets, Language[] languages, bool deep, bool compareRevisions);

Here's an example:

    var domainUser = @"sitecore\admin";

    if (Sitecore.Security.Accounts.User.Exists(domainUser))
        var user = Sitecore.Security.Accounts.User.FromName(domainUser, false);

        using (new Sitecore.Security.Accounts.UserSwitcher(user))
            PublishManager.PublishItem(item, webDatabaseArray, languagesArray, false, false);
catch (Exception ex)
    Sitecore.Diagnostics.Log.Error(ex.Message, null);

Kevin is right, there is no publish task available in the API. The expectation is that there will be a workflow in place and the moving from state to state would be a business process. Handling that in the API would be custom.

If you don't have a workflow in place, I suggest you just turn on the publishing task. If you don't already have it turned on. This will publish the items on a schedule basis.

        <agent type="Sitecore.Tasks.PublishAgent">
            <!-- The time format is "HH:MM:SS" -->
            <!-- Auto-Publish every 6 hrs HCG-C6 -->
            <patch:attribute name="interval">06:00:00</patch:attribute>
            <param desc="source database">master</param>
            <param desc="target database">web</param>
            <param desc="mode (full or smart or incremental)">smart</param>
            <param desc="languages">en</param>

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.