AssignRole

View as Markdown

AssignRole

AssignByRole identifies one role that a workflow stage assigns to an entry. You add it to the AssignedByRoles list of an EntryWorkflowStage.

When to Use This Class: Use this class when SetWorkflow should assign the entry to every user who has a role, for example the reviewers of a team.

Conceptual Role: Acts as the data model that the SDK sends as one item of the assigned_by_roles array in a set entry workflow stage request.

Returns: AssignByRole. One assigned role.

Properties

NameTypeRequiredDefaultDescription
Uidstring?NonullUID of the role. Sent as uid.
Namestring?NonullName of the role. Sent as name.

Class-Level Notes

What the SDK sends.

  • The SDK sends every property that is not null and checks none of them. The API rejects a role UID that the stack does not have.
  • See Set entry workflow stage in the Content Management API (CMA) reference.

Method Index

AssignByRole has no methods. Set its properties and add it to EntryWorkflowStage.AssignedByRoles.

Class-Level Snippet

The snippet below assigns an entry to one role at a workflow stage.

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>");

EntryWorkflowStage stage = new EntryWorkflowStage
{
    Uid = "<WORKFLOW_STAGE_UID>",
    AssignedByRoles = new List<AssignByRole>
    {
        new AssignByRole { Uid = "<ROLE_UID>", Name = "Content Manager" }
    }
};

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").SetWorkflow(stage);
    Console.WriteLine(response.OpenJsonObjectResponse()["notice"]);
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}