BranchModel

View as Markdown

BranchModel

BranchModel holds the details of a branch. You set Uid and Source to create a branch with the Create method, and 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.

Class-Level Notes

Fields you send and fields the API sets.

  • Create and CreateAsync serialize every field that is not null and leave out the null ones. Leave CreatedBy, UpdatedBy, CreatedAt, UpdatedAt, and Alias unset when you create a branch, so the request body contains only uid and source.
  • The model has no field for publish_config, so a branch you create through this SDK clones all environments of its source branch.

Dates are strings.

  • CreatedAt and UpdatedAt contain the timestamp string the API returns. Parse them with DateTimeOffset.Parse when you need a date value.

Method Index

BranchModel has no methods. Set and read its properties directly, and pass the model to the Create method.

Class-Level Snippet

This snippet builds a model to create a branch, then reads a fetched 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>", "<API_HOST>");
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 ex)
{
    Console.WriteLine($"API error {(int)ex.StatusCode}: {ex.ErrorMessage}");
}
NameTypeDescription
Uid string

Branch UID. Required to create a branch. Lowercase, _ between words, at most 15 characters. Serialized as uid.

Source string

UID of the branch to copy, for example main. Required to create a branch. Serialized as source.

CreatedBy string

UID of the user who created the branch. The API sets it. Serialized as created_by.

UpdatedBy string

UID of the user who last updated the branch. The API sets it. Serialized as updated_by.

CreatedAt string

Creation time as an ISO 8601 string. The API sets it. Serialized as created_at.

UpdatedAt string

Last update time as an ISO 8601 string. The API sets it. Serialized as updated_at.

Alias List<BranchAliasModel>

Aliases that point to the branch. The API sets it. Serialized as alias.