Workflow

View as Markdown

Workflow

The Workflow class creates, fetches, lists, updates, enables, disables, and deletes the workflows of a stack, and gives access to its publish rules.

When to Use This Class: Use this class to set up or change the review stages of a stack, for example to add a legal review stage.

Conceptual Role: Acts as the Content Management API (CMA) client for the /workflows endpoint. Call stack.Workflow() to get an instance.

Returns: Workflow. An object for workflow operations.

Instance State

The UID you pass to stack.Workflow() decides which methods you can call on the instance:

  • Call stack.Workflow() without a UID to work with the workflow collection, for example FindAll or Create.
  • Call stack.Workflow("<WORKFLOW_UID>") to work with one workflow, for example Fetch or Disable.
  • Call PublishRule, GetPublishRule, or GetPublishRuleAsync on either instance. They ignore the workflow UID.

If you call a method from the other group, it throws before any request leaves the SDK. A collection method on an instance that has a UID throws InvalidOperationException, and a single-workflow method on an instance with no UID throws ArgumentException. The Method Index below lists every method in each group.

Warning The SDK treats an empty string as no UID for its checks, but still adds it to the request path. stack.Workflow("") allows Create and FindAll, which then send their requests to /workflows/ with a trailing slash. Pass null, or call stack.Workflow() with no argument, when you mean the collection.

Class-Level Notes

Authentication.

  • stack.Workflow() throws InvalidOperationException when the client has no authtoken and the stack has no management token.
  • The CMA reference accepts a management token for every workflow request except Update, which lists the authtoken as required.

Requests and responses.

  • Every method that sends a request returns the raw API response as a ContentstackResponse. A single workflow sits under the workflow key, and the list from FindAll sits under the workflows key.
  • Create and Update serialize a WorkflowModel under the workflow key and leave out its null properties.

Publish rules.

  • A publish rule belongs to a workflow stage, but the API stores publish rules in their own collection. Use PublishRule to get a PublishRule object, and GetPublishRule to read the rules of one content type.

Capability Matrix

CapabilitySupportedNotes / Alternative
Set the workflow stage of an entryNot on this classUse the SetWorkflow method of Entry.
Send, approve, or reject a publish requestNot on this classUse the PublishRequest method of Entry.
List the workflow tasks assigned to youNoThe SDK has no method for the CMA Get all Tasks request.
Pass query parameters to Enable or DisableNoBoth methods take no arguments.

Method Index

Work with the workflow collection. Available on stack.Workflow() when you pass no UID.

Method NameReturnsDescription
FindAllThe API response with the workflows in the stack.Lists every workflow in the stack.
FindAllAsyncThe API response with the workflows in the stack.Lists every workflow in the stack asynchronously.
CreateThe API response with the created workflow.Creates a workflow.
CreateAsyncThe API response with the created workflow.Creates a workflow asynchronously.

Work with one workflow. Available on stack.Workflow("<WORKFLOW_UID>").

Method NameReturnsDescription
FetchThe API response with the requested workflow.Retrieves one workflow.
FetchAsyncThe API response with the requested workflow.Retrieves one workflow asynchronously.
UpdateThe API response with the updated workflow.Replaces the details and stages of a workflow.
UpdateAsyncThe API response with the updated workflow.Replaces the details and stages of a workflow asynchronously.
DisableThe API response with the disabled workflow.Disables a workflow.
DisableAsyncThe API response with the disabled workflow.Disables a workflow asynchronously.
EnableThe API response with the enabled workflow.Enables a workflow.
EnableAsyncThe API response with the enabled workflow.Enables a workflow asynchronously.
DeleteThe API response with the deletion notice.Deletes a workflow.
DeleteAsyncThe API response with the deletion notice.Deletes a workflow asynchronously.

Work with publish rules. Available on stack.Workflow() and on stack.Workflow("<WORKFLOW_UID>").

Method NameReturnsDescription
PublishRuleA new publish rule object.Returns an object for publish rule operations.
GetPublishRuleThe API response with the publish rules of the content type.Retrieves the publish rules of one content type.
GetPublishRuleAsyncThe API response with the publish rules of the content type.Retrieves the publish rules of one content type asynchronously.

Class-Level Snippet

This snippet creates a two-stage workflow, lists the workflows in the stack, and disables the new workflow.

using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
Stack stack = client.Stack("<API_KEY>");

WorkflowModel model = new WorkflowModel()
{
    Name = "Editorial Review",
    ContentTypes = new List<string> { "blog_post" },
    WorkflowStages = new List<WorkflowStage>
    {
        new WorkflowStage() { Name = "Draft", Color = "#2196f3" },
        new WorkflowStage() { Name = "Ready to Publish", Color = "#74ba76" }
    }
};

try
{
    ContentstackResponse created = await stack.Workflow().CreateAsync(model);
    string? workflowUid = created.OpenJsonObjectResponse()["workflow"]?["uid"]?.GetValue<string>();

    ContentstackResponse list = await stack.Workflow().FindAllAsync();
    JsonArray? workflows = list.OpenJsonObjectResponse()["workflows"]?.AsArray();
    Console.WriteLine($"Workflows in the stack: {workflows?.Count}");

    // Turn the new workflow off without deleting its stages
    await stack.Workflow(workflowUid).DisableAsync();
}
catch (ContentstackErrorException e)
{
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

Methods

Each method of the Workflow class has its own section below, with its parameters, validation rules, behavior, and examples.

Create

Create creates a workflow with the stages, content types, and branches you set in the model.

NameTypeDescription
model (required)WorkflowModel

Sets the workflow name, stages, content types, and branches.

Default: Not applicable
collectionParameterCollection?

Adds query parameters to the request.

Default: null

Returns: ContentstackResponse. The API response with the created workflow.

Validation

  • Throws InvalidOperationException if the instance has a UID, because Create posts to the workflow collection. Call stack.Workflow() with no UID.
  • Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
  • The SDK does not check the properties of model. The API validates them.
  • Throws ContentstackErrorException when the API rejects the request, for example a content type UID that does not exist in the stack.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one POST request to /workflows, with model serialized under a workflow key. See Create a workflow in the Content Management API (CMA) reference.
  • Leaves every null property of model out of the request body.
  • Always sends enabled, because Enabled is a bool that defaults to true. Set Enabled = false to create the workflow in a disabled state.
  • Adds the entries of collection to the query string. null or an empty collection adds none.
  • Returns the raw API response. The created workflow, with its UID and the UID of each stage, sits under the workflow key.

Example

Basic usage: create a two-stage workflow

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().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: create a workflow with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

WorkflowModel model = new WorkflowModel()
{
    Name = "Editorial Review",
    ContentTypes = new List<string> { "blog_post" },
    WorkflowStages = new List<WorkflowStage>
    {
        new WorkflowStage() { Name = "Draft", Color = "#2196f3" },
        new WorkflowStage() { Name = "Ready to Publish", Color = "#74ba76" }
    }
};

// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow().Create(model, collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Edge case: calling Create on an instance that has a UID

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",
    ContentTypes = new List<string> { "blog_post" },
    WorkflowStages = new List<WorkflowStage>
    {
        new WorkflowStage() { Name = "Draft", Color = "#2196f3" },
        new WorkflowStage() { Name = "Ready to Publish", Color = "#74ba76" }
    }
};

try
{
    // Create adds a new workflow, so call it on Workflow() with no UID.
    client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Create(model);
}
catch (InvalidOperationException e)
{
    // Fires before any request, because the instance has a UID
    Console.WriteLine(e.Message);
}

CreateAsync

CreateAsync creates a workflow with the stages, content types, and branches you set in the model, without blocking the calling thread.

NameTypeDescription
model (required)WorkflowModel

Sets the workflow name, stages, content types, and branches.

Default: Not applicable
collectionParameterCollection?

Adds query parameters to the request.

Default: null

Returns: Task<ContentstackResponse>. The API response with the created workflow.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws InvalidOperationException if the instance has a UID, because CreateAsync posts to the workflow collection. Call stack.Workflow() with no UID.
  • Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
  • The SDK does not check the properties of model. The API validates them.
  • The SDK throws the client-side exceptions above when you call CreateAsync, before it returns a task. An API rejection surfaces when you await the task.
  • Throws ContentstackErrorException when the API rejects the request, for example a content type UID that does not exist in the stack.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Completes the task when the API responds.
  • Otherwise behaves like Create.

Example

Basic usage: create a two-stage workflow

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 = await client.Stack("<API_KEY>").Workflow().CreateAsync(model);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: create a workflow with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

WorkflowModel model = new WorkflowModel()
{
    Name = "Editorial Review",
    ContentTypes = new List<string> { "blog_post" },
    WorkflowStages = new List<WorkflowStage>
    {
        new WorkflowStage() { Name = "Draft", Color = "#2196f3" },
        new WorkflowStage() { Name = "Ready to Publish", Color = "#74ba76" }
    }
};

// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow().CreateAsync(model, collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Delete

Delete deletes one workflow from the stack.

NameTypeDescription
collectionParameterCollection?

Adds query parameters to the request.

Default: null

Returns: ContentstackResponse. The API response with the deletion notice.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because Delete removes one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one DELETE request to /workflows/<WORKFLOW_UID>. See Delete workflow in the Content Management API (CMA) reference.
  • Adds the entries of collection to the query string. null or an empty collection adds none.
  • Returns the raw API response.

Warning Deleting a workflow removes the workflow and its stages from the stack. The SDK offers no way to restore it. To stop a workflow and keep its stages, use the Disable method instead.

Example

Basic usage: delete a workflow

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

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Delete();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: delete a workflow with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Delete(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

DeleteAsync

DeleteAsync deletes one workflow from the stack, without blocking the calling thread.

NameTypeDescription
collectionParameterCollection?

Adds query parameters to the request.

Default: null

Returns: Task<ContentstackResponse>. The API response with the deletion notice.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because DeleteAsync removes one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • The SDK throws the client-side exceptions above when you call DeleteAsync, before it returns a task. An API rejection surfaces when you await the task.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Completes the task when the API responds.
  • Otherwise behaves like Delete.

Warning Deleting a workflow removes the workflow and its stages from the stack. The SDK offers no way to restore it. To stop a workflow and keep its stages, use the Disable method instead.

Example

Basic usage: delete a workflow

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

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").DeleteAsync();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: delete a workflow with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").DeleteAsync(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Authentication: use a management token instead of an authtoken

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient();

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow("<WORKFLOW_UID>").DeleteAsync();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Disable

Disable disables one workflow, so that its stages no longer apply to entries.

This method takes no parameters.

Returns: ContentstackResponse. The API response with the disabled workflow.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because Disable acts on one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • Throws ContentstackErrorException when the API rejects the request, for example a workflow UID that does not exist.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one GET request to /workflows/<WORKFLOW_UID>/disable. See Disable workflow in the Content Management API (CMA) reference.
  • Sends no request body and no query parameters.
  • Returns the raw API response.

Example

Basic usage: disable a workflow

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Disable();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

Authentication: use a management token instead of an authtoken

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient();

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow("<WORKFLOW_UID>").Disable();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Edge case: calling Disable without a workflow UID

using System;
using Contentstack.Management.Core;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    client.Stack("<API_KEY>").Workflow().Disable();
}
catch (ArgumentException e)
{
    // Fires before any request, because the instance has no workflow UID
    Console.WriteLine(e.Message);
}

DisableAsync

DisableAsync disables one workflow, so that its stages no longer apply to entries, without blocking the calling thread.

This method takes no parameters.

Returns: Task<ContentstackResponse>. The API response with the disabled workflow.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because DisableAsync acts on one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • The SDK throws the client-side exceptions above when you call DisableAsync, before it returns a task. An API rejection surfaces when you await the task.
  • Throws ContentstackErrorException when the API rejects the request, for example a workflow UID that does not exist.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Completes the task when the API responds.
  • Otherwise behaves like Disable.

Example

Basic usage: disable a workflow

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").DisableAsync();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

Authentication: use a management token instead of an authtoken

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient();

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow("<WORKFLOW_UID>").DisableAsync();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Enable

Enable enables one workflow, so that its stages apply to entries again.

This method takes no parameters.

Returns: ContentstackResponse. The API response with the enabled workflow.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because Enable acts on one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • Throws ContentstackErrorException when the API rejects the request, for example a workflow UID that does not exist.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one GET request to /workflows/<WORKFLOW_UID>/enable. See Enable workflow in the Content Management API (CMA) reference.
  • Sends no request body and no query parameters.
  • Returns the raw API response.

Example

Basic usage: enable a workflow

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Enable();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

Authentication: use a management token instead of an authtoken

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient();

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow("<WORKFLOW_UID>").Enable();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Edge case: calling Enable without a workflow UID

using System;
using Contentstack.Management.Core;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    client.Stack("<API_KEY>").Workflow().Enable();
}
catch (ArgumentException e)
{
    // Fires before any request, because the instance has no workflow UID
    Console.WriteLine(e.Message);
}

EnableAsync

EnableAsync enables one workflow, so that its stages apply to entries again, without blocking the calling thread.

This method takes no parameters.

Returns: Task<ContentstackResponse>. The API response with the enabled workflow.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because EnableAsync acts on one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • The SDK throws the client-side exceptions above when you call EnableAsync, before it returns a task. An API rejection surfaces when you await the task.
  • Throws ContentstackErrorException when the API rejects the request, for example a workflow UID that does not exist.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Completes the task when the API responds.
  • Otherwise behaves like Enable.

Example

Basic usage: enable a workflow

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").EnableAsync();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

Authentication: use a management token instead of an authtoken

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient();

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow("<WORKFLOW_UID>").EnableAsync();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Fetch

Fetch retrieves the details of one workflow, including its stages.

NameTypeDescription
collectionParameterCollection?

Adds query parameters to the request.

Default: null

Returns: ContentstackResponse. The API response with the requested workflow.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because Fetch reads one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one GET request to /workflows/<WORKFLOW_UID>. See Get a single workflow in the Content Management API (CMA) reference.
  • Adds the entries of collection to the query string. null or an empty collection adds none.
  • Returns the raw API response. The workflow sits under the workflow key.

Example

Basic usage: fetch a workflow and print its stages

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

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Fetch();
    Console.WriteLine(response.OpenJsonObjectResponse()["workflow"]?["workflow_stages"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: fetch a workflow with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Fetch(collection);
    Console.WriteLine(response.OpenJsonObjectResponse()["workflow"]?["workflow_stages"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Authentication: use a management token instead of an authtoken

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient();

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow("<WORKFLOW_UID>").Fetch();
    Console.WriteLine(response.OpenJsonObjectResponse()["workflow"]?["workflow_stages"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

FetchAsync

FetchAsync retrieves the details of one workflow, including its stages, without blocking the calling thread.

NameTypeDescription
collectionParameterCollection?

Adds query parameters to the request.

Default: null

Returns: Task<ContentstackResponse>. The API response with the requested workflow.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because FetchAsync reads one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • The SDK throws the client-side exceptions above when you call FetchAsync, before it returns a task. An API rejection surfaces when you await the task.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Completes the task when the API responds.
  • Otherwise behaves like Fetch.

Example

Basic usage: fetch a workflow and print its stages

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

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").FetchAsync();
    Console.WriteLine(response.OpenJsonObjectResponse()["workflow"]?["workflow_stages"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: fetch a workflow with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").FetchAsync(collection);
    Console.WriteLine(response.OpenJsonObjectResponse()["workflow"]?["workflow_stages"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

FindAll

FindAll retrieves every workflow in the stack.

NameTypeDescription
collectionParameterCollection?

Adds query parameters, for example filters.

Default: null

Returns: ContentstackResponse. The API response with the workflows in the stack.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws InvalidOperationException if the instance has a UID, because FindAll lists the workflow collection. Call stack.Workflow() with no UID.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one GET request to /workflows. See Get all workflows in the Content Management API (CMA) reference.
  • Adds the entries of collection to the query string. null or an empty collection adds none.
  • Returns the raw API response. The workflows sit under the workflows key.

Example

Basic usage: list the workflows in a stack

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

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow().FindAll();
    Console.WriteLine(response.OpenJsonObjectResponse()["workflows"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: list workflows with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow().FindAll(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Authentication: use a management token instead of an authtoken

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient();

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow().FindAll();
    Console.WriteLine(response.OpenJsonObjectResponse()["workflows"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

FindAllAsync

FindAllAsync retrieves every workflow in the stack, without blocking the calling thread.

NameTypeDescription
collectionParameterCollection?

Adds query parameters, for example filters.

Default: null

Returns: Task<ContentstackResponse>. The API response with the workflows in the stack.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws InvalidOperationException if the instance has a UID, because FindAllAsync lists the workflow collection. Call stack.Workflow() with no UID.
  • The SDK throws the client-side exceptions above when you call FindAllAsync, before it returns a task. An API rejection surfaces when you await the task.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Completes the task when the API responds.
  • Otherwise behaves like FindAll.

Example

Basic usage: list the workflows in a stack

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

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow().FindAllAsync();
    Console.WriteLine(response.OpenJsonObjectResponse()["workflows"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: list workflows with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow().FindAllAsync(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

GetPublishRule

GetPublishRule retrieves the publish rules that apply to one content type, for the action you name in collection.

NameTypeDescription
contentType (required)string

UID of the content type whose rules you want.

Default: Not applicable
collection (required)ParameterCollection

Query parameters, including the required action.

Default: Not applicable

Returns: ContentstackResponse. The API response with the publish rules of the content type.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentNullException (parameter contentType) if contentType is null or an empty string, because the request path needs a content type UID.
  • collection has no default, so you must pass it. The SDK does not check its entries and does not add action for you. The Content Management API (CMA) reference marks action as required, with the value publish or unpublish.
  • Passing null for collection sends no query parameters. In a project with nullable reference types on, the compiler warns about the null argument.
  • The SDK does not check the workflow UID of the instance, so stack.Workflow() works.
  • Throws ContentstackErrorException when the API rejects the request, for example a content type UID that does not exist.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one GET request to /workflows/content_type/<CONTENT_TYPE_UID>, with the entries of collection in the query string. See Get publish rules by content types in the CMA reference.
  • Ignores the workflow UID of this instance. The API selects publish rules by content type, not by workflow.
  • The CMA reference lists the following three query parameters for this request:
    • action (required): publish or unpublish.
    • locale (optional): the locale code the rule applies to.
    • environment (optional): the UID of the environment the rule applies to.
  • Returns the raw API response.

Example

Basic usage: get the publish rules for publishing entries of a content type

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("action", "publish");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow().GetPublishRule("<CONTENT_TYPE_UID>", collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: filter the rules by action, locale, and environment

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("action", "unpublish");
collection.Add("locale", "en-us");
collection.Add("environment", "<ENVIRONMENT_UID>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow().GetPublishRule("<CONTENT_TYPE_UID>", collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Authentication: use a management token instead of an authtoken

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient();

ParameterCollection collection = new ParameterCollection();
collection.Add("action", "publish");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow().GetPublishRule("<CONTENT_TYPE_UID>", collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Edge case: an empty content type UID

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("action", "publish");

try
{
    client.Stack("<API_KEY>").Workflow().GetPublishRule("", collection);
}
catch (ArgumentNullException e)
{
    // Fires before any request, because contentType is null or empty
    Console.WriteLine(e.Message);
}

GetPublishRuleAsync

GetPublishRuleAsync retrieves the publish rules that apply to one content type, for the action you name in collection, without blocking the calling thread.

NameTypeDescription
contentType (required)string

UID of the content type whose rules you want.

Default: Not applicable
collection (required)ParameterCollection

Query parameters, including the required action.

Default: Not applicable

Returns: Task<ContentstackResponse>. The API response with the publish rules of the content type.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentNullException (parameter contentType) if contentType is null or an empty string, because the request path needs a content type UID.
  • collection has no default, so you must pass it. The SDK does not check its entries and does not add action for you. The Content Management API (CMA) reference marks action as required, with the value publish or unpublish.
  • Passing null for collection sends no query parameters. In a project with nullable reference types on, the compiler warns about the null argument.
  • The SDK does not check the workflow UID of the instance, so stack.Workflow() works.
  • The SDK throws the client-side exceptions above when you call GetPublishRuleAsync, before it returns a task. An API rejection surfaces when you await the task.
  • Throws ContentstackErrorException when the API rejects the request, for example a content type UID that does not exist.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Completes the task when the API responds.
  • Otherwise behaves like GetPublishRule.

Example

Basic usage: get the publish rules for publishing entries of a content type

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("action", "publish");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow().GetPublishRuleAsync("<CONTENT_TYPE_UID>", collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: filter the rules by action, locale, and environment

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("action", "unpublish");
collection.Add("locale", "en-us");
collection.Add("environment", "<ENVIRONMENT_UID>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow().GetPublishRuleAsync("<CONTENT_TYPE_UID>", collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

PublishRule

PublishRule returns a PublishRule object that manages the publish rules of the stack, or one publish rule when you pass its UID.

NameTypeDescription
uidstring?

Selects one publish rule. Omit it for the collection.

Default: null

Returns: PublishRule. A new publish rule object.

Validation

  • The SDK does not check uid. A UID that names no publish rule reaches the API when you call a method on the returned object, and the API rejects that call.

Behavior

  • Sends no request. The request happens when you call a method such as FindAll or Fetch on the returned object.
  • Ignores the workflow UID of this instance. The publish rule paths are /workflows/publishing_rules and /workflows/publishing_rules/<PUBLISH_RULE_UID>, so stack.Workflow().PublishRule() and stack.Workflow("<WORKFLOW_UID>").PublishRule() return equivalent objects.
  • Passing no UID, or null, returns an object for the publish rule collection. Passing a UID returns an object for one publish rule. See the PublishRule class for the methods on each.

Example

Basic usage: list the publish rules of a stack

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow().PublishRule().FindAll();
    Console.WriteLine(response.OpenJsonObjectResponse()["publishing_rules"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: fetch one publish rule by UID

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

PublishRule rule = client.Stack("<API_KEY>").Workflow().PublishRule("<PUBLISH_RULE_UID>");

try
{
    ContentstackResponse response = await rule.FetchAsync();
    Console.WriteLine(response.OpenJsonObjectResponse()["publishing_rule"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Update

Update replaces the details of a workflow, including its stages, with the values in the model.

NameTypeDescription
model (required)WorkflowModel

Sets the full workflow, including every stage to keep.

Default: Not applicable
collectionParameterCollection?

Adds query parameters to the request.

Default: null

Returns: ContentstackResponse. The API response with the updated workflow.

Validation

  • Throws ArgumentException (parameter uid) if the instance has no UID, because Update changes one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one PUT request to /workflows/<WORKFLOW_UID>, with model serialized under a workflow key. See Add or update workflow details in the Content Management API (CMA) reference.
  • Leaves every null property of model out of the request body.
  • Always sends enabled, because Enabled is a bool that defaults to true. A model built without Enabled = false enables a disabled workflow.
  • The CMA reference marks the authtoken as required for this request. Create the stack without a management token when you update a workflow.
  • Adds the entries of collection to the query string. null or an empty collection adds none.
  • Returns the raw API response. The updated workflow sits under the workflow key.

Example

Basic usage: add a stage to a workflow

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

// Update sends the whole workflow. Include every stage you want to keep.
WorkflowModel model = new WorkflowModel()
{
    Name = "Editorial Review",
    ContentTypes = new List<string> { "blog_post", "author" },
    WorkflowStages = new List<WorkflowStage>
    {
        new WorkflowStage() { Uid = "<WORKFLOW_STAGE_UID>", Name = "Draft", Color = "#2196f3" },
        new WorkflowStage() { Name = "Legal Review", Color = "#ff9800" },
        new WorkflowStage() { Name = "Ready to Publish", Color = "#74ba76" }
    }
};

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Update(model);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: update a workflow with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

WorkflowModel model = new WorkflowModel()
{
    Name = "Editorial Review",
    ContentTypes = new List<string> { "blog_post" },
    WorkflowStages = new List<WorkflowStage>
    {
        new WorkflowStage() { Name = "Draft", Color = "#2196f3" },
        new WorkflowStage() { Name = "Ready to Publish", Color = "#74ba76" }
    }
};

// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Update(model, collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

UpdateAsync

UpdateAsync replaces the details of a workflow, including its stages, with the values in the model, without blocking the calling thread.

NameTypeDescription
model (required)WorkflowModel

Sets the full workflow, including every stage to keep.

Default: Not applicable
collectionParameterCollection?

Adds query parameters to the request.

Default: null

Returns: Task<ContentstackResponse>. The API response with the updated workflow.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
  • Throws ArgumentException (parameter uid) if the instance has no UID, because UpdateAsync changes one workflow. Call stack.Workflow("<WORKFLOW_UID>").
  • Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
  • The SDK throws the client-side exceptions above when you call UpdateAsync, before it returns a task. An API rejection surfaces when you await the task.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Completes the task when the API responds.
  • Otherwise behaves like Update.

Example

Basic usage: add a stage to a workflow

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

// Update sends the whole workflow. Include every stage you want to keep.
WorkflowModel model = new WorkflowModel()
{
    Name = "Editorial Review",
    ContentTypes = new List<string> { "blog_post", "author" },
    WorkflowStages = new List<WorkflowStage>
    {
        new WorkflowStage() { Uid = "<WORKFLOW_STAGE_UID>", Name = "Draft", Color = "#2196f3" },
        new WorkflowStage() { Name = "Legal Review", Color = "#ff9800" },
        new WorkflowStage() { Name = "Ready to Publish", Color = "#74ba76" }
    }
};

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").UpdateAsync(model);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: update a workflow with a query parameter collection

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

WorkflowModel model = new WorkflowModel()
{
    Name = "Editorial Review",
    ContentTypes = new List<string> { "blog_post" },
    WorkflowStages = new List<WorkflowStage>
    {
        new WorkflowStage() { Name = "Draft", Color = "#2196f3" },
        new WorkflowStage() { Name = "Ready to Publish", Color = "#74ba76" }
    }
};

// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").UpdateAsync(model, collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}