How to get a custom subdomain for your Sitecore Content Hub instance.

You have a baby girl at home, but you want her to be potty trained?

You have a narrow garage and don’t have space to get out of your car after you park?

You just got a new phone but now you have to use Bluetooth headphones and they don’t fit inside your ear hole?

These are the problems I can’t help you with today. But I can help you by letting you know how to get a subdomain for your Content Hub instance.

  • you want to get a custom subdomain name for your content hub instance. so that it looks nicer and branded and easier to remember. Let’s say you want https://topaz.sitecorecontenthub.cloud
  • It’s a simple process. Create a Sitecore ticket. Follow the below screenshot when creating and Hank wil be your uncle.
  • That should be it. if there is anything I will come back here and edit the post.

~ If you put all your junk in your garage, you will have no room left for your cars. ~

Content Hub Web SDK – Programmatically update assets in Content hub from items in Sitecore

Getting the entity

IEntity entity = await _connector.Client.Entities.GetAsync(long.Parse(assetId));

assetId can be a string or a long. The string is mostly used when IDs look like an alphanumeric hash. If we want an image with asset Id of 99551 then use long.

Getting a relationship with an entity

IRelation relation = entity.GetRelation("AssetTypeToAsset");
IList<long> values = relation.GetIds();
//if (values.Count == 0) then we know there is no value set, otherwise there is already a value set for that relation

Setting up a related value

IEntity imageAssetEntity = await _connector.Client.Entities.GetAsync("M.AssetType.Custom");
IChildToOneParentRelation assetEntityRelation = await entity.GetRelationAsync<IChildToOneParentRelation>("AssetTypeToAsset");
assetEntityRelation.Parent = imageAssetEntity.Id.Value;
//This will set up the selected asset entity's AssetType as Custom

Set a property for an entity

string alt = item["Alt"] ?? "";
ICultureInsensitiveProperty altProperty = entity.GetProperty<ICultureInsensitiveProperty>("Alt");
altProperty.SetValue(alt);
//This will get the Alt field value of an item from sitecore and update an asset with that value in the Alt property

Sitecore Content Hub – Find an asset from the public link

I am using Content hub 4.2 and the client wants to know the asset ID, but all we have on the front end is the public key. With Anna‘s help, I got the below solution to work.

Step 1: Get the auth token

Make a POST call to https://subdomain.sitecorecontenthub.cloud/api/authenticate

JSON body should look like below

{
    "user_name": "topaz.ahmed@perficient.com",
    "password": "Vizient+2023"
}

This will return a token like below

{
    "token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}

Step 2: Search for the public link

Suppose you have a public link that looks like

https://subdomain.sitecorecontenthub.cloud/api/public/content/qwertyuiopasdfghjklzxcvbnm?v=1

make a GET call to the below URL

https://subdomain.sitecorecontenthub.cloud/api/entities/query?query=Definition.Name==’M.PublicLink&#8217; AND FullText==’qwertyuiopasdfghjklzxcvbnm‘&skip=0&take=1

In the header of the call using the token from the previous step as X-Auth-Token

If the public link is found in Content Hub this will return JSON that looks something like this.

{
    "items": [
        {
            "id": 44923,
            "identifier": "95HiyeSDa0etMK3ZTMbofQ",
            "cultures": [
                "en-US"
            ],
            "properties": {
                "RelativeUrl": "eaeb36c088054d79b34636ef4e1e73dc",
                "Resource": "downloadOriginal",
                "ResourceType": "content",
                "VersionHash": "f1fd3bd2",
                "IsDisabled": false,
                "ExpirationDate": null,
                "Status": "Completed",
                "Progress": "The link is currently active.",
                "FileKey": "local-3dc41bebf9eb4788a4e85248efaffb6e",
                "ConversionConfiguration": null,
                "PublishStatus": null,
                "PublishStatusDetails": null
            },
            "relations": {
                "FileToPublicLink": {
                    "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/relations/FileToPublicLink"
                },
                "AssetToPublicLink": {
                    "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/relations/AssetToPublicLink"
                },
                "ThemeToPublicLinks": {
                    "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/relations/ThemeToPublicLinks"
                },
                "OrderToPublicLink": {
                    "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/relations/OrderToPublicLink"
                },
                "PageToPublicLink": {
                    "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/relations/PageToPublicLink"
                },
                "PublicLinkToWhereUsed": {
                    "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/relations/PublicLinkToWhereUsed"
                },
                "PublicLinkToUsage": {
                    "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/relations/PublicLinkToUsage"
                }
            },
            "created_by": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/6729",
                "title": "The user who created the entity"
            },
            "created_on": "2023-02-28T16:11:16.4232379Z",
            "modified_by": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/6",
                "title": "The user who last modified the entity"
            },
            "modified_on": "2023-02-28T16:11:20.7346984Z",
            "entitydefinition": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entitydefinitions/M.PublicLink",
                "title": "The entity definition for this entity"
            },
            "copy": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/copy",
                "title": "Copy this entity"
            },
            "permissions": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/permissions",
                "title": "The permissions on this entity"
            },
            "lifecycle": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/lifecycle",
                "title": "The lifecycle action for this entity."
            },
            "saved_selections": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/savedselections",
                "title": "The saved selections this entity belongs to"
            },
            "roles": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/roles",
                "title": "Roles for this entity"
            },
            "annotations": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/annotations",
                "title": "Annotations for this entity"
            },
            "is_root_taxonomy_item": false,
            "is_path_root": false,
            "inherits_security": true,
            "is_system_owned": false,
            "version": 2,
            "self": {
                "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923"
            },
            "renditions": {},
            "public_link": "https://<subdomain>.sitecorecontenthub.cloud/api/public/content/eaeb36c088054d79b34636ef4e1e73dc?v=f1fd3bd2"
        }
    ],
    "total_items": 1,
    "returned_items": 1,
    "offset": 0,
    "self": {
        "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/query?skip=0&take=1&query=Definition.Name%3D%3D%27M.PublicLink%27%20AND%20FullText%3D%3D%27eaeb36c088054d79b34636ef4e1e73dc%27",
        "title": "This collection"
    }
}

Find the URL in the AssetToPublicLink relation.

Step 3: Find the asset

Grab the AssetToPublicLink URL from. use the same header as above and make a GET request.

you will a response like below

{
    "parents": [
        {
            "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/66666"
        }
    ],
    "inherits_security": true,
    "self": {
        "href": "https://<subdomain>.sitecorecontenthub.cloud/api/entities/44923/relations/AssetToPublicLink"
    }
}

And there you go. 66666 is the Asset ID.

Enjoy it while it lasts, I mean until a new version of the API gets released and things change.

~ UPS is better than FEDEX. ~

Use JSON path when setting up a Trigger condition in Sitecore Content Hub

The problem

Create public links for a specific rendition of all assets except for when a document is created or uploaded.

The brain

All assets have file properties that are part of the system OOTB metadata.

I know a trigger on asset change and action that runs a script is the easiest way to get this done. We could add conditions on a trigger to check the asset type relation and then run a script to create a public link. if all else fails look at a custom solution.

The struggle

Trying to load an asset and its related media and types is a little icky. You can read the entity and try to find the type. If it’s an image, video, or document one can decide to run different tasks. FileType, fileName, and File Property metadata all are accessible but a little convoluted to get and check. So I picked a GUI path and just check the asset file property on the trigger condition. so the trigger won’t even fire let alone check inside the script for a valid scenario.

This was a simple solution, but the only problem was finding an example of how to read JSON values in conditions. Thus I gave birth to this blog post. Just type in property names in the path field and trigger works as expected.

Related links to click if you need to.

https://doc.sitecore.com/ch/en/users/34/content-hub/manage–ootb-schema.html

https://www.sitecored.com/2021/09/sitecore-content-hub-automatically-assign-asset-type.html

~ Do not overdo it. If you can, you will do it. If you can’t, someone else will do it. ~