3

For testing purposes we would like to create publish and remove some items in Sitecore using a remote testing- client in C#. Sitecore.Services.Client api seems the most logical way to create and delete items.

But how can I publish an item remotely?

  • I assume you are not using the new Publishing Service yet? – Gatogordo Dec 22 '16 at 10:16
  • Publishing Service is Sitecore 8.2 only right? – Gluip Dec 22 '16 at 12:59
  • Yep. Was asking because it is a separate service that you should be able to trigger through a rest api (although I haven't done that myself yet) – Gatogordo Dec 22 '16 at 13:01
  • Thats a good observation. Surely something we have to consider after upgrading. – Gluip Dec 22 '16 at 13:13
  • An update on this topic, we have created a module that implements a secured Publish method using SSC. nishtechinc.com/en/Blog/2019/July/SscPublish – Rodrigo Peplau Jul 9 '19 at 14:19
3

An easy option would be to create your own webapi controller and create an action that does the publish, using the Sitecore API: Sitecore.Publishing.PublishManager.PublishItem(...) You can pass the item id as a parameter and fetch it from the master database. Other options for the Publish function can be parameterized as well, depending on how flexible you want/need it.

Just be careful that not everyone can start publishing your items, think about security ;)

As you are using the SSC, it should be possible to add custom actions to it: https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/sitecoreservicesclient/use_the_restful_api_for_the_entityservice

Edit: apparently Mike Robbins already blogged on how to add a custom action to your SSC: https://mikerobbins.co.uk/2015/03/20/sitecore-entity-service-ssc-custom-controller-action/ - so you can create a custom action and use the Publish method from the Sitecore API in it.

Some info from the blog:

Entity Service is very flexible allowing you to extend the service controller with additional actions. To add an additional action it is as simple as adding a new function to the service controller, and decorating it with an ActionName and the action type such as HttpGet

If you like the repository pattern that Sitecore have put in place with Entity Service using the IRepository interface and rather keep all the logic of my controller in a single place (in the repository): update the repository to include the extra functional we want to add to the Entity Service.

With custom controller actions in Entity Service, the routing is configured to respond to {Controller-Namespace}/{Controller}/{ID}/{CustomActionName}. If you do not include in an ID in the URL, Entity Service will not resolve to your custom controller action. Uou can then call your controller by using the prefixed of “/sitecore/api/ssc”.

| improve this answer | |
  • Thanks for the idea. Extending an existing service is a nice option! – – Gluip Dec 27 '16 at 6:39

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.