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’ 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. ~