Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Catalog service

Describes how to work with bulk operations for catalog items and elements.

The Optimizely Service API supports the bulk import of catalog data into Optimizely Commerce.

Catalog bulk import and export

In the following we describe the methods to use when importing and exporting catalog files.

Generate the catalog XML file

For the catalog import and export to work as described here, you need to generate an XML file named catalog.xml and place it at the root of a zip file to be uploaded. See Catalog service XML for how to generate the XML file used when importing and exporting catalog data.

Bulk import with file

POSTpost/episerverapi/commerce/import/catalogWhen using this method you receive a backwards-compatible catalog file that will import the content into Commerce.

C# code sample

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", "Catalog.zip");
    var response = client.PostAsync("/episerverapi/commerce/import/catalog", 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

The file to be used is based of the upload identifier of a file previously updated using /episerverapi/commerce/import/upload/chunk and /episerverapi/commerce/import/upload/commit, see Chunk upload of large files.

POSTpost/episerverapi/commerce/import/catalog/{uploadId}When using this method you receive a backwards-compatible catalog file that will import the content into Commerce.

C# code sample

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\""

Bulk export

GETget/episerverapi/commerce/export/catalog/{catalogName}This method returns a zip file of the exported content of the catalog specified in the name parameter.

C# code sample

using (var client = new HttpClient())
  {
    client.BaseAddress = new Uri("https://mysite.com/");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    var response = client.GetAsync("/episerverapi/commerce/export/catalog/{name}").Result;
    if (response.StatusCode == HttpStatusCode.OK)
      {
        var zip = response.Content.ReadAsStreamAsync().Result;
        zip.CopyTo(File.Create("output.zip"));
      }
  }