PublishRuleModel
PublishRuleModel
PublishRuleModel holds the details of a publish rule: the workflow stage it belongs to, its approvers, and the content types, locales, environment, and branches it covers. Pass it to the Create or Update method of PublishRule.
When to Use This Class: Use this class to build the request body when you create or change a publish rule.
Conceptual Role: Acts as the data model that PublishRule serializes under the publishing_rule key of a request.
Returns: PublishRuleModel. The details of a publish rule.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| WorkflowUid | string? | No | null | UID of the workflow the rule belongs to. Serialized as workflow. |
| WorkflowStageUid | string? | No | null | UID of the workflow stage the rule applies to. Serialized as workflow_stage. |
| Actions | List<string>? | No | null | Actions the rule covers. Serialized as actions. |
| ContentTypes | List<string>? | No | null | UIDs of the content types the rule covers. Serialized as content_types. |
| Locales | List<string>? | No | null | Codes of the locales the rule covers. Serialized as locales. |
| Environment | string? | No | null | UID of the environment the rule covers. Serialized as environment. |
| Branches | List<string>? | No | null | UIDs of the branches the rule covers. Serialized as branches. |
| Approvers | Approvals? | No | null | Users and roles who approve, as an Approvals object. Serialized as approvers. |
| DisableApproval | bool | No | false | Serialized as disable_approver_publishing. |
Class-Level Notes
What the SDK sends.
- The SDK leaves every null property out of the request body.
- DisableApproval is a bool, so the SDK always sends disable_approver_publishing, as false unless you set it.
- The property names differ from the JSON keys for three properties: WorkflowUid is workflow, WorkflowStageUid is workflow_stage, and DisableApproval is disable_approver_publishing.
Additional Resource Refer to Create publish rules for the request body.
Method Index
PublishRuleModel has no methods. Set its properties and pass it to the Create or Update method of PublishRule.
Class-Level Snippet
This snippet builds a publish rule that needs approval before blog posts publish to an environment, 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>");
PublishRuleModel model = new PublishRuleModel()
{
WorkflowUid = "<WORKFLOW_UID>",
WorkflowStageUid = "<WORKFLOW_STAGE_UID>",
Actions = new List<string> { "publish" },
ContentTypes = new List<string> { "blog_post" },
Locales = new List<string> { "en-us" },
Environment = "<ENVIRONMENT_UID>",
Branches = new List<string> { "main" },
Approvers = new Approvals()
{
Users = new List<string> { "<USER_UID>" },
Roles = new List<string> { "<ROLE_UID>" }
},
DisableApproval = false
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Workflow().PublishRule().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse()["publishing_rule"]?["uid"]);
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}