LabelModel
LabelModel
LabelModel holds the details of a label: its name, the UIDs of its parent labels, and the UIDs of the content types it groups. Pass it to the Create and Update methods of Label.
When to Use This Class: Use this class to build the request for a new or changed label, or to read a fetched label as a typed object.
Conceptual Role: Acts as the data model that the Label class serializes under the label key of a request body.
Returns: LabelModel. The details of a label.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Name | string? | No | null | Name of the label. Serialized as name. |
| Parent | List<string>? | No | null | UIDs of the parent labels. Serialized as parent. |
| ContentTypes | List<string>? | No | null | UIDs of the content types in the label. Serialized as content_types. |
Class-Level Notes
Fields the SDK sends.
- The SDK leaves out every property that is null, so the request body holds only the properties you set.
- The SDK checks none of the properties. The Add label and Update label requests of the Content Management API reference list the details a label takes.
- LabelModel has no Uid property. The API assigns the UID of a new label, and the Label instance carries the UID of the label you update.
Reading a fetched label.
- Deserialize the label node of a Fetch response into LabelModel to read Name, Parent, and ContentTypes. Read other fields of the response, such as uid, from the JSON.
Method Index
LabelModel has no methods. Set and read its properties directly, and pass the object to the Create or Update method.
Class-Level Snippet
The snippet below creates a child label under an existing parent label and groups two content types in it.
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>");
LabelModel model = new LabelModel
{
Name = "Campaigns",
Parent = new List<string> { "<PARENT_LABEL_UID>" },
ContentTypes = new List<string> { "blog_post", "landing_page" }
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Label().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse()["label"]?["uid"]);
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}