ManagementTokenModel
ManagementTokenModel
ManagementTokenModel holds the details of a management token: its name, description, scope, expiry, and email notification setting. Pass it to the Create or Update method of ManagementToken.
When to Use This Class: Use this class to build the request body for a management token.
Conceptual Role: Acts as the data model that ManagementToken serializes under the token key of a request. Its namespace is Contentstack.Management.Core.Models.Token.
Returns: ManagementTokenModel. The details of a management token.
Known issue The ManagementToken class, which takes this model, builds its request path from /delivery_tokens, not from stacks/management_tokens, the path the Content Management API reference gives for management tokens. Requests from it do not reach the management token endpoints. Manage management tokens through the Content Management API directly.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Name | string | No | null | Name of the token. Serialized as name. |
| Description | string | No | null | Description of the token. Serialized as description. |
| Scope | List<TokenScope> | No | null | Modules, branches, and permissions of the token, as TokenScope items. Serialized as Scope, with a capital S. |
| ExpiresOn | string | No | null | Expiry date and time of the token, in UTC. Serialized as expires_on. |
| IsEmailNotificationEnabled | bool | No | false | true asks the API to email a reminder before the token expires. Serialized as is_email_notification_enabled. |
Class-Level Notes
Nullability.
- The SDK declares the string and List properties without ? and gives them no initial value, so each one holds null until you set it. The SDK leaves null properties out of the request body.
- IsEmailNotificationEnabled is a bool, so the SDK always sends it.
Scope key.
- Scope serializes under the JSON key Scope, while DeliveryTokenModel.Scope serializes under scope. When you call the management token requests of the API directly, send the scope under the key that the API reference shows.
Additional Resource Refer to Create management token for the request body.
Method Index
ManagementTokenModel has no methods. Set its properties and pass it to the Create or Update method of ManagementToken.
Class-Level Snippet
This snippet builds a management token model with a content type scope and an expiry date. The ManagementToken methods do not reach the management token endpoints in version 1.2.0.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ManagementTokenModel model = new ManagementTokenModel()
{
Name = "Content Migration",
Description = "Read-write access for the migration script",
Scope = new List<TokenScope>
{
new TokenScope()
{
Module = "content_type",
ACL = new Dictionary<string, string> { ["read"] = "true", ["write"] = "true" }
},
new TokenScope()
{
Module = "branch",
Branches = new List<string> { "main" },
ACL = new Dictionary<string, string> { ["read"] = "true" }
}
},
ExpiresOn = "2027-06-30T23:59:59.000Z",
IsEmailNotificationEnabled = true
};
try
{
// In version 1.2.0 this request goes to /delivery_tokens. See the ManagementToken class page.
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}