Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
ImportAsset; POST /episerverapi/commerce/import/assets
This actually returns the task id (guid) for use in status request, so this wouldn't be the assetkey as this endpoint supports zip files, which could have more than one asset.
This is likely the issue when trying to do the asset linking and with it unable to find the media.
ItemAsset; POST /episerverapi/commerce/entries/{code}/assets
The {code} part is actually the entrycode or the "catalog entry code"/sku
Offical docs show this clearly:
var model = new ItemAsset()
{
CatalogEntryCode = "Jackets-Blazers-Wrap",
AssetKey = "fd761c1d-5692-48b6-b90a-1ddf4c7c5eb9",
AssetType = "episerver.core.icontentimage",
SortOrder = 45,
GroupName = "large"
};
var json = JsonConvert.SerializeObject(model);
var client = new HttpClient()
{
BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
};
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
var result = client.PostAsync("/episerverapi/commerce/entries/{entry code}/assets",
new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result
Thanks for your input; I neglected to look further than the "swagger"-like overview on the following page: https://world.optimizely.com/documentation/class-libraries/rest-apis/service-api/#/ImportExport/ImportCommerceAssetsFile
I assumed the fact that I could include a binary meant that the binary was a single specific asset of which one could then link to an entry. I have since discovered that this endpoint has a much larger function than simply uploading a single asset: https://docs.developers.optimizely.com/customized-commerce/v1.3.0-service-api-developer-guide/docs/media-service
While I would argue that the function of the asset import endpoint diverts away from the RESTful approach of the rest of the API, the important conclusion here is to read the documentation more thouroughly 😃
/Stephen
I am trying to link a newly uploaded asset to an entry using the following endpoints:
ImportAsset; POST /episerverapi/commerce/import/assets
ItemAsset; POST /episerverapi/commerce/entries/{code}/assets
The result of the ImportAsset appears to work, as I get a Guid response I am assuming is the AssetKey of the uploaded asset in Optimizely.
But when I try linking that asset to an entry with the ItemAsset request (obviously using the AssetKet retreived from the ImportAsset response) I get the following error from Commerce:
What am I doing wrong?
/Stephen