Hide menu Last updated: Oct 20 2016
Area: Episerver Service API Applies to versions: 1 and higher

CMS content import service

EPiServer.ServiceApi Services lets you import CMS content through an episerverdata file into Episerver Commerce. See Setting up EPiServer.ServiceApi and Overview of EPiServer.ServiceApi, for information about installing and configuring the service API.

CMS import methods

CMS site bulk import with file

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.

C#
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

episerverapi/commerce/import/cms/site/{siteName}/{hostname}/{uploadId:guid}/{culture=}
For this method to work, you need a valid upload identifier of the episerverdata file previously uploaded using the chunked upload methods. The culture is an optional parameter if you want to set the culture for the hostname of the site.

C#
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 assets bulk import with file

episerverapi/commerce/import/cms/assetglobalroot
Use this method if you have exported your assets into an episerverdata file using the export assets tool. This will put your assets under the global assets root.
C#
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 site bulk import with file upload identifier

episerverapi/commerce/import/cms/assetglobalroot/{uploadId:guid}
Use this method if you have exported your assets into an episerverdata file using the export assets tool. This will put 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.
C#
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

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 will export from the root.

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

}

Comments