REST API that will auto publish the Sitecore item and then push the item to the initial workflow state

Sitecore workflows are meant to setup a process in the content edit capability of the system. In other words, they are meant to be triggered by human intervention while moving content from one state to another. This process needs to be handled by different roles in terms of moving the content item from one state to another after careful consideration aka review/approval. However, Sitecore is a open system or in other words, the system is highly configurable and so, you can plugin your own logic for workflow. In this blog note, I cover such a route wherein when the user hits a REST API endpoint with an item id, the item will be automatically moved from a draft state to published content and thereafter the state will be reset to an initial state so that another workflow (probably along-with human intervention) can pick up the item for any further processing. Although this process itself sounds quirky/dangerous, the idea of this note is to show how such a transition is possible but since the whole thing sounds hacky, the approach isn't advisable to say the list.

Three states to the workflow:

1. Draft: Needed for the workflow default setup

2. Auto: This is the transient state that will be assigned for the master item

3. Initial: This is the auto-reverted state after publishing the item to web db

REST API Code:

All the code will stay here. Sitecore will be used only to create the workflow and different states so that the item ids can be used in this code:

/////

The publish and revert state logic:
////+++
///+++

Sitecore workflow and states:


Demo:

Github code - tested on Sitecore 10.4.1 instance

Comments