This section describes how to work with bulk operations when using the Episerver Service API, a service layer used for integration of Episerver with external systems, such as PIM, DAM and ERPs.
How it works
Integrations with for example PIM systems often involve transfer of large data volumes. The Service API allows for bulk operations that can take a long time to complete. To facilitate this, a bulk operation returns a task identifier that you can use to get the task's status and associated messages.
Example model
using System;
public enum MessageType
{
Progress = 0,
Debug = 1,
Info = 2,
Warning = 3,
Success = 4,
Error = 5
}
public class JobMessage
{
public DateTime TimestampUtc { get; set; }
public MessageType MessageType { get; set; }
public string Message { get; set; }
public string StageName { get; set; }
public int StageIndex { get; set; }
public int StageCount { get; set; }
public int StageProgress { get; set; }
public int StageTotalProgress { get; set; }
public string ExceptionMessage { get; set; }
public string ExceptionStackTrace { get; set; }
}
Note: Only consider a task completed if the message type is number 4 or 5.
Get task status
episerverapi/commerce/task/{taskId:guid}/status This method gets the last status message of the associated task identifier.
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/task/{guid}/status", content).Result;
}
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://mysite.com/");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
var response = client.GetAsync("/episerverapi/commerce/task/{guid}/status", content).Result;
}
episerverapi/commerce/task/{taskId:guid}/log This method gets the the status messages of the associated task identifier.
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/task/{guid}/log", content).Result;
}
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://mysite.com/");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
var response = client.GetAsync("/episerverapi/commerce/task/{guid}/log", content).Result;
}