ExtensionModel

View as Markdown

ExtensionModel

ExtensionModel holds the title, type, source, and settings of an extension. Pass it to the Create and Update methods of Extension to add or change an extension with a source URL or with source code.

When to Use This Class: Use this class for an extension whose code another server hosts, or whose source code you send as a string. To upload an HTML file instead, use CustomFieldModel, CustomWidgetModel, or DashboardWidgetModel.

Conceptual Role: Acts as the data model that Extension serializes under the extension key of a request body.

Returns: ExtensionModel. The settings of an extension.

Properties

NameTypeRequiredDefaultDescription
Titlestring?NonullName of the extension. Serialized as title.
DataTypestring?NonullData type a custom field stores, for example text. Serialized as data_type.
TagsList<string>?NonullTags for the extension. Serialized as tags.
Srcstring?NonullURL of an extension that another server hosts. Serialized as src.
Srcdocstring?NonullSource code that Contentstack hosts. Serialized as srcdoc.
Typestring?NonullKind of extension, for example field or widget. Serialized as type.
Configstring?NonullConfiguration of the extension, as a string. Serialized as config.
MultipleboolNofalseWhether a custom field stores multiple values. Serialized as multiple.
ScopeExtensionScope?NonullContent types that show a widget. Serialized as scope.

Class-Level Notes

Fields the SDK sends.

  • The SDK leaves out every property that is null. Multiple is a bool, so the SDK always sends it, as false when you do not set it.
  • The SDK checks none of the properties. The Create a custom field with source URL request of the Content Management API reference lists the properties the API expects.

Values of Type.

  • The Content Management API reference names the five extension types listed below:
    • field for a custom field
    • widget for a custom widget
    • dashboard for a dashboard widget
    • rte_plugin for a JSON Rich Text Editor plugin
    • asset_sidebar_widget for an asset sidebar extension

Settings without a property.

  • ExtensionModel has no property for the enable and default_width settings of a dashboard widget, or for the width and blur effect of an asset sidebar extension. Upload a dashboard widget with DashboardWidgetModel to set its width and state.

Method Index

ExtensionModel has no methods. Set and read its properties directly, and pass the object to the Create or Update method.

Class-Level Snippet

The snippet below builds a model for a custom field that another server hosts, then creates the extension.

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

ExtensionModel model = new ExtensionModel
{
    Title = "Star Rating",
    Type = "field",
    DataType = "number",
    Tags = new List<string> { "rating" },
    Src = "https://example.com/star-rating.html",
    Config = "{\"maxStars\": 5}",
    Multiple = false
};

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Extension().Create(model);
    Console.WriteLine(response.OpenJsonObjectResponse()["extension"]?["uid"]);
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}