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
- Download the package for your corresponding Sitecore version from here;
- 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}
- ItemId = your item ID (without brackets)
- 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
- deep (bool) - Deep publish
Default: false - async (bool) - Async publish
Default: false - targetDb (string) - Target Database
Default: “web” - mode (string) - Publish Mode
Default: “SingleItem”
Example calls
- Publish with default values: http://yourserver/sitecore/api/ssc/SscPublish.Controllers/Publish/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9/
- 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:
- Full - Re-publishes everything
- Incremental - Every item change generates a record in list (f.e. PublishingQueue table). List is inspected during publishing
- SingleItem - Publishes single item
- Smart - Publishes items that have difference in source and target
- Unknown - Unknown mode