WorkflowModel
WorkflowModel
WorkflowModel holds the details of a workflow: its name, stages, content types, branches, and owners. Pass it to the Create or Update method of Workflow.
When to Use This Class: Use this class to build the request body when you create or change a workflow.
Conceptual Role: Acts as the data model that Workflow serializes under the workflow key of a request.
Returns: WorkflowModel. The details of a workflow.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Name | string? | No | null | Name of the workflow. Serialized as name. |
| Enabled | bool | No | true | Turns the workflow on or off. Serialized as enabled. |
| Branches | List<string>? | No | null | UIDs of the branches the workflow applies to. Serialized as branches. |
| ContentTypes | List<string>? | No | null | UIDs of the content types the workflow applies to. Serialized as content_types. |
| AdminUsers | Dictionary<string, object>? | No | null | Owners of the workflow, as the API's admin_users object. |
| WorkflowStages | List<WorkflowStage>? | No | null | Stages of the workflow, as WorkflowStage items. Serialized as workflow_stages. |
Class-Level Notes
What the SDK sends.
- The SDK leaves every null property out of the request body.
- Enabled is a bool, so the SDK always sends it. An Update call with a model that leaves Enabled at its default of true enables the workflow.
- The SDK does not check any property. The API validates the model when it receives the request.
Additional Resource Refer to Create a workflow for the request body.
Method Index
WorkflowModel has no methods. Set its properties and pass it to the Create or Update method of Workflow.
Class-Level Snippet
This snippet builds a two-stage workflow for the blog_post content type and creates it.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
WorkflowModel model = new WorkflowModel()
{
Name = "Editorial Review",
Enabled = true,
Branches = new List<string> { "main" },
ContentTypes = new List<string> { "blog_post" },
AdminUsers = new Dictionary<string, object> { ["users"] = new List<object>() },
WorkflowStages = new List<WorkflowStage>
{
new WorkflowStage()
{
Name = "Draft",
Color = "#2196f3",
NextAvailableStages = new List<string> { "$all" },
EntryLock = "$none",
SystemACL = new Dictionary<string, object>
{
["roles"] = new Dictionary<string, object> { ["uids"] = new List<string>() },
["users"] = new Dictionary<string, object> { ["uids"] = new List<string> { "$all" } },
["others"] = new Dictionary<string, object>()
}
},
new WorkflowStage()
{
Name = "Ready to Publish",
Color = "#74ba76",
NextAvailableStages = new List<string> { "$all" },
EntryLock = "$none",
SystemACL = new Dictionary<string, object>
{
["roles"] = new Dictionary<string, object> { ["uids"] = new List<string>() },
["users"] = new Dictionary<string, object> { ["uids"] = new List<string> { "$all" } },
["others"] = new Dictionary<string, object>()
}
}
}
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Workflow().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse()["workflow"]?["uid"]);
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}