blog

Sitecore Content Hub - add custom setting (M.Setting)

When customizing your Sitecore Content Hub instance, you may want to configure your own environment settings, e.g. to store keys and tokens for external services you want to integrate. Here you can find two ways to add your own M.Setting entities.

Posted: 2/19/2020

When customizing your Sitecore Content Hub instance, you may want to configure your own environment settings, e.g. to store keys and tokens for external services you want to integrate. There is not much information on how to do this in official Content Hub docs and it took me quite a long time to figure it out. Below you can find two ways to add your own M.Setting entities.

Using REST API

As you may know from Sitecore Content Hub REST API documentation, it is possible to create new entities by using POST request to the endpoint:

https://{{hostname}}/api/entities/

I decided to check if it’s possible to create a new M.Setting entity this way. Following the existing settings and taking into account the required fields, I prepared an example JSON body for POST request:

{
    "identifier": "M.Setting.Twitter",
    "is_root_taxonomy_item": false,
    "cultures": [
        "en-US"
    ],
    "properties": {
        "M.Setting.Name": "Twitter",
        "M.Setting.Value": {
            "ApiKey": "",
            "ApiSecretKey": "",
            "AccessToken": "",
            "AccessTokenSecret": ""
        }
    },
    "relations": {
        "SettingCategoryToSettings": {
            "parent": {
                "href": "https://{{hostname}}/api/entities/6858"
            },
            "inherits_security": true
        }
    },
    "entitydefinition": {
        "href": "https://{{hostname}}/api/entitydefinitions/M.Setting",
        "title": "The entity definition for this entity"
    }
}

And it worked! Here’s the line-by-line description:

  • Line 2: your custom setting identitifier (required) - should have M.Setting prefix (naming convention).
  • Line 8: name of your setting (required).
  • Lines 9-14: values of your setting (required). If you’re not sure what fields your setting should contain, leave the brace empty (you can edit it later).
  • Line 19: 6858 stands for Integration category. If you want to place your setting under another category, check its id and paste it here.
  • Line 25: set entity definition as M.Setting.

Now you can check in portal - your new setting is in place and available for further editing.

A new setting ready to be filled in with values.

Remember! You need to be authenticated in the API to successfully execute this request.

In Portal

There is also an alternative way to create new settings - directly in portal. It’s not in the documentation so you need to know exact url:

https://{{hostname}}/en-us/admin/entitymgmt/entities/1

After moving to the indicated address, a page with all M.Setting entities is displayed.

”Secret” view with all setting entities.

You can add a new setting by clicking the ”+” icon in the right corner. You will be directed to the page with a form that you can fill with exactly the same values as in the first example, but using a more user-friendly view.

In portal setting creation.


Hero photo by Jonathan Borba on Unsplash