StackSettings

View as Markdown

StackSettings

StackSettings holds the settings that the AddSettings method of Stack sends to a stack.

When to Use This Class: Use this class to turn a stack setting on or off, for example to keep entry URLs unique across the stack.

Conceptual Role: Acts as the request body of Stack.AddSettings and Stack.AddSettingsAsync. The SDK sends it inside a stack_settings key.

Returns: StackSettings. The settings to send to a stack.

Class-Level Notes

Each property is a dictionary of API-defined keys.

  • The SDK does not check the keys or values. The API decides which keys it accepts. See Add stack settings in the Content Management API reference.
  • The Content Management API reference lists stack variables such as enforce_unique_urls and sys_rte_allowed_tags. Setting enforce_unique_urls to true keeps entry URLs unique across the stack. The sys_rte_allowed_tags variable accepts a combination of figure, style, and script.
  • A property you leave null stays out of the request body.

When the SDK deserializes JSON into StackSettings, for example through OpenTResponse<T>() with a type that holds a StackSettings property, it turns JSON strings, numbers, and booleans in these dictionaries into string, long or double, and bool values. Objects and arrays stay JsonElement values.

Properties

NameTypeRequiredDefaultDescription
StackVariablesDictionary<string, object>?NonullStack variables. Serialized as stack_variables.
DiscreteVariablesDictionary<string, object>?NonullDiscrete variables. Serialized as discrete_variables.
RteDictionary<string, object>?NonullRich text editor settings. Serialized as rte.

Method Index

StackSettings has no methods. Set its properties and pass it to the methods named above.

Class-Level Snippet

The snippet below turns on unique entry URLs and allows the figure tag in the rich text editor.

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

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

StackSettings settings = new StackSettings()
{
    StackVariables = new Dictionary<string, object>()
    {
        { "enforce_unique_urls", true },
        { "sys_rte_allowed_tags", "figure" }
    }
};

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