Loading...
Area: Optimizely Service API
Applies to versions: 1 and higher

CMS content import service

Recommended reading 

This topic describes how to bulk import Optimizely CMS content into Optimizely Commerce, using the CMS content import service in the Optimizely Service API.

How it works

To import content using the CMS content import service, the content is imported through an episerverdata file, the format for data used for exports from Optimizely CMS, see Overview of Service API.

CMS import methods

CMS site bulk import with file

The culture is an optional parameter if you want to set the culture for the hostname of the site.

post/episerverapi/commerce/import/cms/site/{siteName}/{hostname}/{culture}

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", "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.

The culture is an optional parameter if you want to set the culture for the hostname of the site.

post/episerverapi/commerce/import/cms/site/{siteName}/{hostname}/{uploadId}/{culture}

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/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

Use 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.

post/episerverapi/commerce/import/cms/assetglobalroot

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

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.

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.

post/episerverapi/commerce/import/cms/assetglobalroot/{uploadId}

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/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

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.

get/episerverapi/commerce/export/site/{siteName}

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"));
      }
  }

Related topics

Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 20, 2016

Recommended reading