BulkAddItemsData

View as Markdown

BulkAddItemsData

BulkAddItemsData holds the release, the action, the locales, and the items of a bulk release request. Pass it to the AddItems, AddItemsWithDeployment, UpdateItems, and UpdateItemsWithDeployment methods of BulkOperation.

When to Use This Class: Use this class to add many entries and assets to a release in one request.

Conceptual Role: Acts as the JSON request body of the /bulk/release/items and /bulk/release/update_items requests.

Returns: BulkAddItemsData. The release and items of a bulk release request.

Properties

NameTypeRequiredDefaultDescription
ItemsList<BulkAddItem>?NonullItems to add. Serialized as items. See BulkAddItem.
Releasestring?NonullUID of the release. Serialized as release.
Actionstring?NonullRelease action, for example publish or unpublish. Serialized as action.
LocaleList<string>?NonullLocale codes of the items. Serialized as locale.
Referencebool?NonullIncludes referenced items when true. Serialized as reference.

Class-Level Notes

Serialization.

  • The SDK serializes the model with System.Text.Json and leaves out every property that is null. The SDK does not check the values.

The request body.

The Content Management API (CMA) reference for the Bulk Add to Release request expects the release UID, the action, the locales, the reference flag, and the items in the body. Set Release and Action before you call AddItems or UpdateItems.

  • AddItemsWithDeployment and UpdateItemsWithDeployment write Release, Action, Locale, and Reference from their arguments and replace the values you set.

Method Index

Method NameReturnsDescription
IsReleaseDeploymentModeTrue when both Release and Action hold a value.Checks whether the model holds a release and an action.

Class-Level Snippet

The snippet below adds one entry, with its references, to a release for publishing.

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

ContentstackClient client = new ContentstackClient();

BulkAddItemsData data = new BulkAddItemsData()
{
    Release = "<RELEASE_UID>",
    Action = "publish",
    Locale = new List<string> { "<LOCALE_CODE>" },
    Reference = true,
    Items = new List<BulkAddItem>
    {
        new BulkAddItem() { Uid = "<ENTRY_UID>", ContentTypeUid = "<CONTENT_TYPE_UID>", Version = 2, Locale = "<LOCALE_CODE>", Title = "Spring Sale" }
    }
};

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").BulkOperation().AddItems(data, "2.0");
    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}");
}

Methods

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

IsReleaseDeploymentMode

IsReleaseDeploymentMode checks whether the model holds both a release UID and an action.

This method takes no parameters.

Returns: bool. True when both Release and Action hold a value.

Validation

  • Throws no exception. It reads two properties of the model.
  • IsReleaseDeploymentMode sends no request, so it raises no API error.

Behavior

  • Returns true when Release and Action are both not null and not empty, and false otherwise.
  • The SDK does not call this method. AddItems and UpdateItems send the model as it is, whatever the result.

Example

Basic usage: check the model before you send it

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

BulkAddItemsData data = new BulkAddItemsData()
{
    Items = new List<BulkAddItem>
    {
        new BulkAddItem() { Uid = "<ENTRY_UID>", ContentTypeUid = "<CONTENT_TYPE_UID>", Version = 1, Locale = "<LOCALE_CODE>", Title = "Spring Sale" }
    }
};

Console.WriteLine(data.IsReleaseDeploymentMode()); // False

data.Release = "<RELEASE_UID>";
data.Action = "publish";
Console.WriteLine(data.IsReleaseDeploymentMode()); // True