In Sitecore, everything is an item and for customization we play around items only. Similarly in Sitecore Content Hub, everything is an Entity and it has Entity definitions. In layman language, you can consider entity definition as an entity attributes/ properties.
In this blog, I would talk about how we can create an asset in the Content Hub programmatically.
If you are new for the Sitecore Content Hub, I would suggest reading my earlier few blogs to have some basic understanding about Sitecore Content Hub.
In my earlier blog, you saw that how we could setup WebClient SDK and the code to establish the connection with Content Hub
Create Asset
User M.Asset entity for performing action on Asset. Use below code to create an asset:
asset.Identifier = "custom_indetifier_tool";
asset.SetPropertyValue("Title", "Custom Asset programmatically.");
var assetId = await CHClient.Client().Entities.SaveAsync(asset).ConfigureAwait(false);
Console.WriteLine($"Asset id: {assetId}");
Connection Successfully established.
Create assets
Asset Id: 31437
It returns the asset id which you have uploaded in DAM. You can see your asset/image using the following URL pattern:
https://< sandbox-link>/en-us/asset/31437
Get Asset
We can get the asset details based on asset Id. Use following code to get the asset details:
IEntity iEntity = await CHClient.Client().Querying.SingleAsync(query);
Connection Successfully established.
Getting asset based on Id: 30832...
Asset Title: Custom Asset programmatically.
Entity Definition: M.Asset
Delete Asset
Delete asset by using following code:
Connection Successfully established.
Asset deleted successfully
After delete if you check the asset URL, you will get the 404 page.
Update Asset
Code for updating asset attributes:
You can check the entire code below:
References:
SITECORE CLI LOGIN ERROR - /.well-known/openid-configuration: Bad Gateway
WALKTHROUGH OF ASP.NET RENDERING SDK
SETTING UP ASP.NET RENDERING SDK
DISABLE SITECORE PUBLISHING SERVICE
SETUP SITECORE PUBLISHING SERVICE
SITECORE CONNECT CONNECTOR - CONTENT HUB