HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

Catalog asset linking service

This topic describes how to import catalog asset links in bulk using the Optimizely Service API.

The catalog asset linking service is an operation that imports catalog item asset data into the Optimizely Commerce database to be used by Commerce components.

How it works

The Service API allows for bulk importing of catalog item asset linking into Optimizely Commerce. A catalog item asset can be for example an image associated with a node/category, product or variant in Optimizely Commerce.

Prerequisites

The import/export process searches for ImageData content in the CMS database. Any asset to be associated with catalog items must be present in the CMS database before running import/export.

Catalog asset linking methods

Bulk import with file

The following catalog asset linking XML shows how to generate the XML needed for the method.

post/episerverapi/commerce/import/links

using (var client = new HttpClient())
  {
    client.BaseAddress = new Uri("https://mysite.com/");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    var content = new MultipartFormDataContent();
    var filestream = new FileStream(path, FileMode.Open);
    content.Add(new StreamContent(filestream), "file", "Linking.xml");
    var response = client.PostAsync("/episerverapi/commerce/import/links", content).Result;
    if (response.StatusCode == HttpStatusCode.OK)
      {
        var returnString = response.Content.ReadAsStringAsync().Result;
        returnString = returnString.Replace("\"", "");
        Guid taskId = Guid.Empty;
        Guid.TryParse(returnString, out taskId);
      }
  }

Response

"\"9e4bd26f-b263-488c-a5d3-3e4c9f87ac4f\""

Bulk import with file upload identifier

For this method to work, you need to a valid upload identifier for an asset linking XML file previously uploaded using the chunked upload methods, see Chunk upload of large files.

POST

post/episerverapi/commerce/import/catalog/{uploadId}

The following Catalog asset linking XML shows how to generate the XML needed for the method.

using (var client = new HttpClient())
  {
    client.BaseAddress = new Uri("https://mysite.com/");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    var response = client.PostAsync(String.Format("episerverapi/commerce/import/catalog/{0}", uploadId), new FormUrlEncodedContent(new List<KeyValuePair<String, String>>())).Result;
    if (response.StatusCode == HttpStatusCode.OK)
      {
        var returnString = response.Content.ReadAsStringAsync().Result;
        returnString = returnString.Replace("\"", "");
        Guid taskId = Guid.Empty;
        Guid.TryParse(returnString, out taskId);
      }
  }

Response

"\"9e4bd26f-b263-488c-a5d3-3e4c9f87ac4f\""

Catalog asset linking XML

The following example shows what a catalog item asset export looks like.

<?xml version="1.0" encoding="utf-8"?>
<CatalogItemAssetCollection>
  <TotalCount>2</TotalCount>
  <CatalogItemAssets>
    <CatalogItemAsset>
      <CatalogItemType>Node</CatalogItemType>
      <CatalogItemCode>testNode</CatalogItemCode>
      <AssetPath>catalogs/mypath</AssetPath>
      <AssetName>nodeAsset.jpg</AssetName>
      <AssetType>episerver.core.icontentimage</AssetType>
      <GroupName>small</GroupName>
      <SortOrder>0</SortOrder>
    </CatalogItemAsset>
    <CatalogItemAsset>
      <CatalogItemType>Entry</CatalogItemType>
      <CatalogItemCode>testVariation</CatalogItemCode>
      <AssetPath>catalogs/mypath</AssetPath>
      <AssetName>variationAsset.jpg</AssetName>
      <AssetType>episerver.core.icontentimage</AssetType>
      <GroupName>small</GroupName>
      <SortOrder>0</SortOrder>
    </CatalogItemAsset>
  </CatalogItemAssets>
</CatalogItemAssetCollection>
  • CatalogItemAssetCollection. Adds catalog asset links to the catalog.
    • TotalCount (required). Number of assets to be linked
    • CatalogItemAssets. Adds catalog asset links to the catalog.
    • CatalogItemAsset. Element to add or update catalog item asset.
      - CatalogItemType (required). The item type (node, entry).
      - CatalogItemCode (required). The code of the entry or node.
      - AssetPath. The path to the asset from the global asset root.
      - AssetName (required). The filename of the asset, including extension.
      - AssetType (required). The type of asset:
      - Image. episerver.core.icontentimage.
      - Other. episerver.core.icontentmedia.
      - GroupName. Way to group assets together for node or entry, (for example, Additional Images).
      - SortOrder (required). The order in which associations are returned.

Did this page help you?