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

Media service

Describes how to work with bulk operations for media type of data.

The Optimizely Service API supports bulk importing of media data such as images into Optimizely Commerce.

Media bulk import methods

In the following we describe the methods to use when importing media files.

Generate the media XML file

For imports using the media service, you can upload an XML file with unc paths or http paths to the media. You also can embed images in a zip file with the media.xml file. See Media service XML.

Bulk import with file

POSTpost/episerverapi/commerce/import/assetsSee Media service XML for how to generate the XML needed for the method.

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", "Media.xml");
  var response = client.PostAsync("/episerverapi/commerce/import/assets", 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 of a catalog.zip file previously uploaded using the chunked upload methods.

POSTpost/episerverapi/commerce/import/assets/{uploadId}See Media service XML for how to generate the XML needed for the method.

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/assets/{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\""