TermMoveModel

View as Markdown

TermMoveModel

TermMoveModel holds the target parent and position of a term for the Move and MoveAsync methods.

When to Use This Class: Use this class to move a term under another parent term, or to change its position among the terms at its level.

Conceptual Role: Acts as the data model that the Term class serializes under the term key of the move request.

Returns: TermMoveModel. The target parent and position of a term.

Properties

NameTypeRequiredDefaultDescription
ParentUidstring?NonullUID of the new parent term. Serialized as parent_uid.
Orderint?NonullPosition among the terms at that level, starting from 1. Serialized as order.

Class-Level Notes

What the SDK sends.

  • The SDK serializes every property that is not null and leaves out the null ones. A model with no ParentUid sends no parent_uid key, and a model with no Order sends no order key.
  • The body therefore cannot carry an explicit "parent_uid": null.

What the API does with it.

The Move/Reorder a term request in the Content Management API reference states that order sets the position of the term among the terms at the same level. The first position is 1.

  • The API rejects the move of a term that has child terms unless the request carries force=true.

Method Index

TermMoveModel has no methods. Set its properties and pass the model to the Move method.

Class-Level Snippet

The snippet below moves a term to the first position under a new parent term, together with its child terms.

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

TermMoveModel moveModel = new TermMoveModel { ParentUid = "<PARENT_TERM_UID>", Order = 1 };

ParameterCollection collection = new ParameterCollection();
collection.Add("force", true);

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Taxonomy("<TAXONOMY_UID>").Terms("<TERM_UID>").Move(moveModel, collection);
    Console.WriteLine((int)response.StatusCode);
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request, for example a move under the term itself
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}