ExtensionScope

View as Markdown

ExtensionScope

ExtensionScope lists the content types whose entries show a custom widget. Set it on ExtensionModel. The CustomWidgetModel constructor also takes one.

When to Use This Class: Use this class to limit a custom widget to some content types, or to apply it to all of them.

Conceptual Role: Acts as the data model for the scope value of a widget.

Returns: ExtensionScope. The content types of a widget.

Properties

NameTypeRequiredDefaultDescription
ContentTypesList<string>?NonullContent type UIDs, or $all for every content type. Serialized as content_types.

Class-Level Notes

Values.

  • The Upload a widget request of the Content Management API reference takes either {"content_types":["$all"]} or a list of content type UIDs.
  • The SDK checks no UID in the list. An unknown content type UID reaches the API.

Serialization.

  • With Create and Update, the SDK sends the scope inside the JSON body under extension.scope.
  • With Upload, CustomWidgetModel serializes the scope to a JSON string and adds it to the form.

Known issue The CustomWidgetModel form part that holds the scope has no field name, so the API does not receive the scope of an uploaded widget. Set the scope through ExtensionModel.Scope and the Create method instead.

Method Index

ExtensionScope has no methods. Set its property directly, and pass the object to ExtensionModel.Scope or to the CustomWidgetModel constructor.

Class-Level Snippet

The snippet below creates a widget that appears on two content types.

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 = "SEO Checker",
    Type = "widget",
    Src = "https://example.com/seo-widget.html",
    Scope = new ExtensionScope { ContentTypes = new List<string> { "blog_post", "landing_page" } }
};

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