ManagementToken
ManagementToken
The ManagementToken class is meant to create, fetch, list, update, and delete the management tokens of a stack. A management token gives read-write access to stack content through the Content Management API (CMA).
When to Use This Class: Use this class to manage the credentials that scripts use to change stack content, once the known issue below has a fix.
Conceptual Role: Acts as the CMA client for management tokens. Call stack.ManagementTokens() to get an instance.
Returns: ManagementToken. An object for management token operations.
Known issue Every method of this class 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.
Instance State
Get an instance with stack.ManagementTokens(), a plural method name. The UID you pass decides which methods you can call:
- Call stack.ManagementTokens() without a UID to work with the token collection, for example Create or Query.
- Call stack.ManagementTokens("<MANAGEMENT_TOKEN_UID>") to work with one token, for example Fetch or Delete.
If you call a method from the other group, it throws before any request leaves the SDK. A collection method on an instance that has a UID throws InvalidOperationException, and a single-token method on an instance with no UID throws ArgumentException. The Method Index below lists every method in each group.
Class-Level Notes
Authentication.
- stack.ManagementTokens() throws InvalidOperationException when the client has no authtoken and the stack has no management token.
- The CMA reference lists only the authtoken for management token requests, and only the owner or an admin of a stack can create a management token.
Requests.
- Create and Update serialize a ManagementTokenModel under the token key and leave out its null properties.
Capability Matrix
| Capability | Supported | Notes / Alternative |
|---|---|---|
| Create, list, update, or delete management tokens | No (known issue) | Call the CMA Management Token requests directly until a fix ships. |
Method Index
Work with the token collection. Available on stack.ManagementTokens() when you pass no UID.
| Method Name | Returns | Description |
|---|---|---|
| Query | A new query for management tokens. | Builds a query meant to list management tokens. |
| Create | The API response with the created management token. | Sends a request meant to create a management token. |
| CreateAsync | The API response with the created management token. | Sends a request meant to create a management token asynchronously. |
Work with one token. Available on stack.ManagementTokens("<MANAGEMENT_TOKEN_UID>").
| Method Name | Returns | Description |
|---|---|---|
| Fetch | The API response with the requested management token. | Sends a request meant to retrieve one management token. |
| FetchAsync | The API response with the requested management token. | Sends a request meant to retrieve one management token asynchronously. |
| Update | The API response with the updated management token. | Sends a request meant to update a management token. |
| UpdateAsync | The API response with the updated management token. | Sends a request meant to update a management token asynchronously. |
| Delete | The API response with the deletion notice. | Sends a request meant to delete a management token. |
| DeleteAsync | The API response with the deletion notice. | Sends a request meant to delete a management token asynchronously. |
Class-Level Snippet
This snippet shows the intended call to create a management token. In version 1.2.0 the request does not reach the management token endpoint.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
Stack stack = client.Stack("<API_KEY>");
ManagementTokenModel model = new ManagementTokenModel()
{
Name = "Content Migration",
Scope = new List<TokenScope>
{
new TokenScope()
{
Module = "content_type",
ACL = new Dictionary<string, string> { ["read"] = "true" }
}
}
};
try
{
// In version 1.2.0 this request goes to /delivery_tokens. See the known issue above.
ContentstackResponse created = await stack.ManagementTokens().CreateAsync(model);
Console.WriteLine(created.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Methods
Each method of the ManagementToken class has its own section below, with its parameters, validation rules, behavior, and examples.
Create
Create is meant to create a management token with the name, scope, and expiry you set in the model.
| Name | Type | Description |
|---|---|---|
| model (required) | ManagementTokenModel | Sets the token name, description, scope, and expiry. |
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: ContentstackResponse. The API response with the created management token.
Known issue Create 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.
Validation
- Throws InvalidOperationException if the instance has a UID, because Create posts to the management token collection. Call stack.ManagementTokens() with no UID.
- Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
- The SDK does not check the properties of model. The API validates them.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST request to /delivery_tokens, with model serialized under a token key. See Create management token in the Content Management API (CMA) reference.
- Leaves every null property of model out of the request body.
- Always sends is_email_notification_enabled, because IsEmailNotificationEnabled is a bool that defaults to false.
- Serializes Scope under the key Scope. See ManagementTokenModel.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Example
Basic usage: create a management token with read-write access to content types
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
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens().Create(model);
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}");
}All parameters: create a management token with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ManagementTokenModel model = new ManagementTokenModel()
{
Name = "Content Migration",
Scope = new List<TokenScope>
{
new TokenScope()
{
Module = "content_type",
ACL = new Dictionary<string, string> { ["read"] = "true" }
}
}
};
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens().Create(model, collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: calling Create on an instance that has a UID
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",
Scope = new List<TokenScope>
{
new TokenScope()
{
Module = "content_type",
ACL = new Dictionary<string, string> { ["read"] = "true" }
}
}
};
try
{
// Create adds a new management token, so call it on ManagementTokens() with no UID.
client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").Create(model);
}
catch (InvalidOperationException e)
{
// Fires before any request, because the instance has a UID
Console.WriteLine(e.Message);
}CreateAsync
CreateAsync is meant to create a management token with the name, scope, and expiry you set in the model, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| model (required) | ManagementTokenModel | Sets the token name, description, scope, and expiry. |
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: Task<ContentstackResponse>. The API response with the created management token.
Known issue CreateAsync 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.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws InvalidOperationException if the instance has a UID, because CreateAsync posts to the management token collection. Call stack.ManagementTokens() with no UID.
- Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
- The SDK does not check the properties of model. The API validates them.
- The SDK throws the client-side exceptions above when you call CreateAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Create.
Example
Basic usage: create a management token with read-write access to content types
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
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens().CreateAsync(model);
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}");
}All parameters: create a management token with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ManagementTokenModel model = new ManagementTokenModel()
{
Name = "Content Migration",
Scope = new List<TokenScope>
{
new TokenScope()
{
Module = "content_type",
ACL = new Dictionary<string, string> { ["read"] = "true" }
}
}
};
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens().CreateAsync(model, collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Delete
Delete is meant to delete one management token from the stack.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: ContentstackResponse. The API response with the deletion notice.
Known issue Delete 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.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because Delete removes one management token. Call stack.ManagementTokens("<MANAGEMENT_TOKEN_UID>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one DELETE request to /delivery_tokens/<MANAGEMENT_TOKEN_UID>. See Delete management token in the Content Management API (CMA) reference.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Warning A successful deletion stops every script and integration that uses the management token. The CMA offers no way to restore it.
Example
Basic usage: delete a management token
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>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").Delete();
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}");
}All parameters: delete a management token with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").Delete(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}DeleteAsync
DeleteAsync is meant to delete one management token from the stack, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: Task<ContentstackResponse>. The API response with the deletion notice.
Known issue DeleteAsync 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.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because DeleteAsync removes one management token. Call stack.ManagementTokens("<MANAGEMENT_TOKEN_UID>").
- The SDK throws the client-side exceptions above when you call DeleteAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Delete.
Warning A successful deletion stops every script and integration that uses the management token. The Content Management API (CMA) offers no way to restore it.
Example
Basic usage: delete a management token
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>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").DeleteAsync();
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}");
}All parameters: delete a management token with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").DeleteAsync(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Fetch
Fetch is meant to retrieve the details of one management token, without the token value.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: ContentstackResponse. The API response with the requested management token.
Known issue Fetch 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.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because Fetch reads one management token. Call stack.ManagementTokens("<MANAGEMENT_TOKEN_UID>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one GET request to /delivery_tokens/<MANAGEMENT_TOKEN_UID>. See Get a single management token in the Content Management API (CMA) reference.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Example
Basic usage: fetch a management token
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>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").Fetch();
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}");
}All parameters: fetch a management token with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").Fetch(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}FetchAsync
FetchAsync is meant to retrieve the details of one management token, without the token value, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: Task<ContentstackResponse>. The API response with the requested management token.
Known issue FetchAsync 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.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because FetchAsync reads one management token. Call stack.ManagementTokens("<MANAGEMENT_TOKEN_UID>").
- The SDK throws the client-side exceptions above when you call FetchAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Fetch.
Example
Basic usage: fetch a management token
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>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").FetchAsync();
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}");
}All parameters: fetch a management token with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").FetchAsync(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Query
Query returns a query object meant to list the management tokens of the stack when you call Find or FindAsync on it.
This method takes no parameters. Chain Limit, Skip, and IncludeCount on the query object, then call Find or FindAsync to send the request.
Returns: Query. A new query for management tokens.
Known issue Query 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.
Validation
- Throws InvalidOperationException if the instance has a UID, because Query lists the management token collection. Call stack.ManagementTokens() with no UID.
- Query sends no request. Errors that do occur come from the Find or FindAsync call that follows, not from Query.
- Find and FindAsync throw InvalidOperationException if the client has no authtoken and the stack has no management token, and ContentstackErrorException when the API rejects the request.
- Limit, Skip, and IncludeCount each add a query parameter to a dictionary that rejects duplicate keys. The SDK throws ArgumentException before any request in the following two cases:
- You chain the same method twice.
- The collection you pass to Find repeats a key that a chained method already set.
- A query object keeps its parameters after Find runs. A second Find call with a collection that repeats a key throws ArgumentException. Build a new query for each request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Find and FindAsync send one GET request to /delivery_tokens, with every parameter you set in the query string. See Get all management tokens in the Content Management API (CMA) reference.
- Returns the raw API response.
- Does not page through the results. Without Limit and Skip, the API applies its own page size. To read the next page, build a new query with a higher Skip value.
- The query object has the five methods below. See the Query class for details.
| Method | Returns | Description |
|---|---|---|
| Limit(double value) | Query | Sets the number of management tokens per page. |
| Skip(double value) | Query | Sets the number of management tokens to skip. |
| IncludeCount() | Query | Adds the total count to the response. |
| Find(ParameterCollection? collection = null) | ContentstackResponse | Sends the request. |
| FindAsync(ParameterCollection? collection = null) | Task<ContentstackResponse> | Sends the request without blocking the calling thread. |
Example
Basic usage: list the management tokens of a stack
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>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens().Query().Find();
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}");
}Paging: read one page with a total count
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>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens()
.Query()
.Limit(10)
.Skip(0)
.IncludeCount()
.FindAsync();
Console.WriteLine($"Total: {response.OpenJsonObjectResponse()["count"]}");
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: setting a query parameter twice
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
Query query = client.Stack("<API_KEY>").ManagementTokens().Query().Limit(5);
ParameterCollection collection = new ParameterCollection();
collection.Add("limit", 10);
try
{
// Limit(5) already set "limit", so adding it again fails.
query.Find(collection);
}
catch (ArgumentException e)
{
// Fires before any request, when a query parameter is set twice
Console.WriteLine(e.Message);
}Update
Update is meant to replace the name, scope, and expiry of a management token with the values in the model.
| Name | Type | Description |
|---|---|---|
| model (required) | ManagementTokenModel | Sets the full token, including its scope and expiry. |
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: ContentstackResponse. The API response with the updated management token.
Known issue Update 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.
Validation
- Throws ArgumentException (parameter uid) if the instance has no UID, because Update changes one management token. Call stack.ManagementTokens("<MANAGEMENT_TOKEN_UID>").
- Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one PUT request to /delivery_tokens/<MANAGEMENT_TOKEN_UID>, with model serialized under a token key. See Update management token in the Content Management API (CMA) reference.
- Leaves every null property of model out of the request body.
- Always sends is_email_notification_enabled, because IsEmailNotificationEnabled is a bool that defaults to false.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Example
Basic usage: extend the expiry of a management token
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
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").Update(model);
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}");
}All parameters: update a management token with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ManagementTokenModel model = new ManagementTokenModel()
{
Name = "Content Migration",
Scope = new List<TokenScope>
{
new TokenScope()
{
Module = "content_type",
ACL = new Dictionary<string, string> { ["read"] = "true" }
}
}
};
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").Update(model, collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}UpdateAsync
UpdateAsync is meant to replace the name, scope, and expiry of a management token with the values in the model, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| model (required) | ManagementTokenModel | Sets the full token, including its scope and expiry. |
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: Task<ContentstackResponse>. The API response with the updated management token.
Known issue UpdateAsync 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.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because UpdateAsync changes one management token. Call stack.ManagementTokens("<MANAGEMENT_TOKEN_UID>").
- Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
- The SDK throws the client-side exceptions above when you call UpdateAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Update.
Example
Basic usage: extend the expiry of a management token
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
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").UpdateAsync(model);
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}");
}All parameters: update a management token with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ManagementTokenModel model = new ManagementTokenModel()
{
Name = "Content Migration",
Scope = new List<TokenScope>
{
new TokenScope()
{
Module = "content_type",
ACL = new Dictionary<string, string> { ["read"] = "true" }
}
}
};
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").UpdateAsync(model, collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}