BranchModel
BranchModel
BranchModel holds the details of a branch. To create a branch with the Create method, set Uid, Source, and optionally PublishConfig. The API fills the other fields when it returns a branch.
When to Use This Class: Use this class to build the request for a new branch, or to read a fetched branch as a typed object.
Conceptual Role: Acts as the data model that the Branch class serializes under the branch key of a request.
Returns: BranchModel. The details of a branch.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Uid | string? | No | null | Branch UID. Lowercase, _ between words, at most 15 characters. Serialized as uid. |
| Source | string? | No | null | UID of the branch to copy, for example main. Serialized as source. |
| CreatedBy | string? | No | null | UID of the user who created the branch. The API sets it. Serialized as created_by. |
| UpdatedBy | string? | No | null | UID of the user who last updated the branch. The API sets it. Serialized as updated_by. |
| CreatedAt | string? | No | null | Creation time as a string. The API sets it. Serialized as created_at. |
| UpdatedAt | string? | No | null | Last update time as a string. The API sets it. Serialized as updated_at. |
| Alias | List<BranchAliasModel>? | No | null | Aliases that point to the branch, as BranchAliasModel items. The API sets it. Serialized as alias. |
| PublishConfig | BranchPublishConfigModel? | No | null | Environments the new branch clones. null clones all environments. Serialized as publish_config. Requires version 1.2.0 or later. |
Class-Level Notes
Fields you send and fields the API sets.
- Create and CreateAsync leave every null property out of the request. Leave CreatedBy, UpdatedBy, CreatedAt, UpdatedAt, and Alias unset, so the body holds only uid, source, and publish_config when you set it.
- The Content Management API (CMA) reference requires a custom UID and the UID of a source branch in the create request.
- Leave PublishConfig unset to clone all environments of the source branch. Set it to a BranchPublishConfigModel to clone only the environments it lists, or none.
Dates are strings.
- CreatedAt and UpdatedAt hold the timestamp string the API returns. Parse them with DateTimeOffset.Parse when you need a date value.
Additional Resource Refer to Create a branch for the request body.
Method Index
BranchModel has no methods. Set and read its properties directly, and pass the model to the Create method of Branch.
Class-Level Snippet
This snippet creates a branch, then reads an existing branch back into a second model.
using System;
using System.Text.Json;
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>");
try
{
BranchModel model = new BranchModel() { Uid = "<BRANCH_UID>", Source = "main" };
stack.Branch().Create(model);
ContentstackResponse response = stack.Branch("<EXISTING_BRANCH_UID>").Fetch();
BranchModel? branch = response.OpenJsonObjectResponse()["branch"]?.Deserialize<BranchModel>();
foreach (BranchAliasModel alias in branch?.Alias ?? new())
{
Console.WriteLine($"Alias {alias.Uid} points to {branch?.Uid}");
}
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}