Securely publish items remotely with Sitecore Services Client (SSC)

written by sitecore\rpeplau

|

July 2019

One of the coolest things with Sitecore are the headless capabilities. Sitecore Services Client (SSC) is one of the available APIs that can be used to read and manipulate data in Sitecore, enabling multiple channels and devices to have access to information managed in Sitecore.

Unfortunately, even though SSC enables reading and writting, it does not provides a way to publish items. Anything created or modified through this API, would either have to be published later, or written directly at the web database. The first takes time and is inconvenient, the second is usually a bad architecture decision.

To cover this gap, Nish Tech has created the SscPublish module. Extending SSC, this module provides a secured API method to publish Sitecore items.

Git Repository

You can browse the source code and download the latest version here:

https://github.com/peplau/SscPublish

Installation

  1. Download the package for your corresponding Sitecore version from here;
  2. Install with Installation Wizard

Post-installation:

Add an entry to ConnectionStrings.config with a SecurityToken to your SSC client:

<name="Sitecore.Services.Token.SecurityKey" connectionString="key=bHN81iFRbluzXGkNNLRqGAlCytp2w9fm"/>

Please, don’t use this secret - instead, create a strong password (Eg: using https://passwordsgenerator.net/)

Calling the SSC method

Follow the pattern:

/sitecore/api/ssc/SscPublish.Controllers/Publish/{itemId}?{parameters}

  1. ItemId = your item ID (without brackets)
  2. parameters = Querystring parameters (Eg: ?async=true&deep=false)

IMPORTANT: In order to execute a publish, the user authenticated to SSC must be a member of the role sitecore\Sitecore Client Publishing

Parameters

  1. deep (bool) - Deep publish
    Default: false
  2. async (bool) - Async publish
    Default: false
  3. targetDb (string) - Target Database
    Default: “web”
  4. mode (string) - Publish Mode
    Default: “SingleItem”

Example calls

  1. Publish with default values: http://yourserver/sitecore/api/ssc/SscPublish.Controllers/Publish/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9/
  2. Deep and Async publish: http://yourserver/sitecore/api/ssc/SscPublish.Controllers/Publish/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9/?deep=true&async=true

Available Publish Modes

The implementation will cast the string passed at the mode parameter into the enum Sitecore.Publishing.PublishMode

Accepted values are:

  1. Full - Re-publishes everything
  2. Incremental - Every item change generates a record in list (f.e. PublishingQueue table). List is inspected during publishing
  3. SingleItem - Publishes single item
  4. Smart - Publishes items that have difference in source and target
  5. Unknown - Unknown mode

 

X
Cookies help us improve your website experience.
By using our website, you agree to our use of cookies.
Confirm