BranchPublishConfigModel

View as Markdown

BranchPublishConfigModel

BranchPublishConfigModel lists the environments a new branch clones. Assign it to BranchModel.PublishConfig before you call the Create or CreateAsync method.

When to Use This Class: Use this class when a new branch needs only some environments of its source branch, or none of them.

Conceptual Role: Acts as the data model that BranchModel serializes under the publish_config key of a branch create request.

Returns: BranchPublishConfigModel. The environment settings of a branch.

Note BranchPublishConfigModel requires version 1.2.0 or later of the .NET Management SDK.

Properties

NameTypeRequiredDefaultDescription
EnvironmentsList<string>?NonullEnvironment names the new branch clones, not environment UIDs. Serialized as environments.

Class-Level Notes

What the list does.

  • A list of environment names clones only those environments.
  • An empty list clones no environments.
  • To clone all environments, leave BranchModel.PublishConfig unset. The SDK then leaves publish_config out of the request.

The API checks the names, not the SDK.

  • The SDK sends the list unchanged and does not check the names or the list length.
  • The API rejects an environment name that does not exist in the stack, alone or mixed with valid names, with 422. The SDK throws that rejection as ContentstackErrorException, and the API creates no branch.
  • The API returns the environment list of the new branch under branch.publish_config.environments in the create response.

Additional Resource Refer to Create a branch for the publish_config request body.

Method Index

BranchPublishConfigModel has no methods. Set its Environments property and assign the model to BranchModel.PublishConfig.

Class-Level Snippet

This snippet creates a branch that clones only the development and staging environments.

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

BranchModel model = new BranchModel()
{
    Uid = "<BRANCH_UID>",
    Source = "main",
    PublishConfig = new BranchPublishConfigModel()
    {
        Environments = new List<string> { "development", "staging" }
    }
};

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Branch().Create(model);
    Console.WriteLine(response.OpenJsonObjectResponse()["branch"]?["publish_config"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}