DeliveryTokenModel

View as Markdown

DeliveryTokenModel

DeliveryTokenModel holds the details of a delivery token: its name, description, and scope. Pass it to the Create or Update method of DeliveryToken.

When to Use This Class: Use this class to build the request body when you create or change a delivery token.

Conceptual Role: Acts as the data model that DeliveryToken serializes under the token key of a request. Its namespace is Contentstack.Management.Core.Models.Token.

Returns: DeliveryTokenModel. The details of a delivery token.

Properties

NameTypeRequiredDefaultDescription
NamestringNonullName of the token. Serialized as name.
DescriptionstringNonullDescription of the token. Serialized as description.
ScopeList<DeliveryTokenScope>NonullEnvironments and branches the token can read, as DeliveryTokenScope items. Serialized as scope.

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.

Additional Resource Refer to Create delivery token for the request body and the scope schema.

Method Index

DeliveryTokenModel has no methods. Set its properties and pass it to the Create or Update method of DeliveryToken.

Class-Level Snippet

This snippet builds a delivery token that can read one environment and the main branch, and creates it.

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>");

DeliveryTokenModel model = new DeliveryTokenModel()
{
    Name = "Production Website",
    Description = "Read-only access to published content in production",
    Scope = new List<DeliveryTokenScope>
    {
        new DeliveryTokenScope()
        {
            Module = "environment",
            Environments = new List<string> { "<ENVIRONMENT_UID>" },
            ACL = new Dictionary<string, string> { ["read"] = "true" }
        },
        new DeliveryTokenScope()
        {
            Module = "branch",
            Branches = new List<string> { "main" },
            ACL = new Dictionary<string, string> { ["read"] = "true" }
        }
    }
};

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").DeliveryToken().Create(model);
    Console.WriteLine(response.OpenJsonObjectResponse()["token"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}