HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Content import service for Optimizely Content Management System

Describes how to import Optimizely Content Management System (CMS) content in bulk to Optimizely Commerce using the CMS content import service in the Optimizely Service API.

The Optimizely Content Management System (CMS) content import service imports content through an episerverdata file, the format for data used for exports from CMS (see Service API Developer Guide).

CMS import methods

CMS site bulk import with file

POSTpost/episerverapi/commerce/import/cms/site/{siteName}/{hostname}/{culture}The culture is an optional parameter if you want to set the culture for the hostname of the site.
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", "Import.episerverdata");
  var response = client.PostAsync("/episerverapi/commerce/import/cms/site/{siteName}/{hostname}/{culture}", 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\""

CMS site bulk import with file upload identifier

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

POSTpost/episerverapi/commerce/import/cms/site/{siteName}/{hostname}/{uploadId}/{culture}The culture is an optional parameter if you want to set the culture for the hostname of the site.
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/cms/{siteName}/{hostname}/{0}/{culture}", 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\""

CMS asset bulk import with file

POSTpost/episerverapi/commerce/import/cms/assetglobalrootUse this method if you have exported your assets into an episerverdata file using the export assets tool. This puts your assets under the global assets root.
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", "Import.episerverdata");
  var response = client.PostAsync("/episerverapi/commerce/import/cms/assetglobalroot", 
  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\""

CMS asset bulk import with file upload identifier

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

POSTpost/episerverapi/commerce/import/cms/assetglobalroot/{uploadId}Use this method if you exported your assets into an episerverdata file using the export assets tool. This puts your assets under the global assets root.
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/cms/assetglobalroot/{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\""

CMS bulk export methods

CMS bulk export

GETget/episerverapi/commerce/export/site/{siteName}This method returns an episerverdata file of the exported contents of the site specified in the site name. If the site is not found, it exports from the root.

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/site/{siteName}").Result;
  if (response.StatusCode == HttpStatusCode.OK)
  {
    var episerverdata = response.Content.ReadAsStreamAsync().Result;
    episerverdata.CopyTo(File.Create("output.episerverdata"));
  }
}