PreviewTokenModel

View as Markdown

PreviewTokenModel

PreviewTokenModel holds the name and description of a preview token. Pass it to the Create method of PreviewToken.

When to Use This Class: Use this class to name the preview token you create for a delivery token.

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

Returns: PreviewTokenModel. The details of a preview token.

Properties

NameTypeRequiredDefaultDescription
Namestring?NonullName of the preview token. Serialized as name.
Descriptionstring?NonullDescription of the preview token. Serialized as description.

Class-Level Notes

What the SDK sends.

  • The SDK leaves a null property out of the request body and does not check either value. The API validates them.

Additional Resource Refer to Create preview token for the request.

Method Index

PreviewTokenModel has no methods. Set its properties and pass it to the Create method of PreviewToken.

Class-Level Snippet

This snippet names a preview token and creates it for a delivery token.

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

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

PreviewTokenModel model = new PreviewTokenModel()
{
    Name = "Live Preview",
    Description = "Preview token for the website Live Preview panel"
};

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