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

Bulk operations

EPiServer.ServiceApi allows for bulk operations that could take long amounts of time to complete. To facilitate this, a bulk operation returns as task identifier that you then can use to get the status and messages associated with the task. Do not consider a task completed unless the message type is number 4 or 5.

Example model

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

Get Task Status

episerverapi/commerce/task/{taskId:guid}/status
This method gets the last status message of the associated task identifier.

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/task/{guid}/status", content).Result;
}
JSON Response
{
  "TimestampUtc": "2014-09-08T10:18:12.8122808Z",
  "MessageType": 4,
  "Message": "Task complete.",
  "StageName": "Import",
  "StageIndex": 1,
  "StageCount": 2,
  "StageProgress": 10000,
  "StageTotalProgress": 10000,
  "ExceptionMessage": null,
  "ExceptionStackTrace": null
}
C#
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;
	
}
XML Response
<JobMessage xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <TimestampUtc>2014-09-08T10:18:12.8122808Z</TimestampUtc>
  <MessageType>Success</MessageType>
  <Message>Task complete.</Message>
  <StageName>Import</StageName>
  <StageIndex>1</StageIndex>
  <StageCount>2</StageCount>
  <StageProgress>10000</StageProgress>
  <StageTotalProgress>10000</StageTotalProgress>
</JobMessage>

Get Task Log

episerverapi/commerce/task/{taskId:guid}/log
This method gets the the status messages of the associated task identifier.

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/task/{guid}/log", content).Result;
}
JSON Response
[
  {
    "TimestampUtc": "2014-09-08T10:18:07.8687819Z",
    "MessageType": 2,
    "Message": "Preparing to unpack zip file.",
    "StageName": "Extract",
    "StageIndex": 0,
    "StageCount": 2,
    "StageProgress": 0,
    "StageTotalProgress": 1,
    "ExceptionMessage": null,
    "ExceptionStackTrace": null
  },
  {
    "TimestampUtc": "2014-09-08T10:18:12.7592472Z",
    "MessageType": 2,
    "Message": "Imported catalog TestCatalog",
    "StageName": "Import",
    "StageIndex": 1,
    "StageCount": 2,
    "StageProgress": 9900,
    "StageTotalProgress": 10000,
    "ExceptionMessage": null,
    "ExceptionStackTrace": null
  },
  {
    "TimestampUtc": "2014-09-08T10:18:12.8102795Z",
    "MessageType": 2,
    "Message": "Import successfully finished.",
    "StageName": "Import",
    "StageIndex": 1,
    "StageCount": 2,
    "StageProgress": 10000,
    "StageTotalProgress": 10000,
    "ExceptionMessage": null,
    "ExceptionStackTrace": null
  },
  {
    "TimestampUtc": "2014-09-08T10:18:12.8122808Z",
    "MessageType": 4,
    "Message": "Task complete.",
    "StageName": "Import",
    "StageIndex": 1,
    "StageCount": 2,
    "StageProgress": 10000,
    "StageTotalProgress": 10000,
    "ExceptionMessage": null,
    "ExceptionStackTrace": null
  }
]
C#
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;
	
}
XML Response
<ArrayOfJobMessage xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <JobMessage>
    <TimestampUtc>2014-09-08T10:18:07.8687819Z</TimestampUtc>
    <MessageType>Info</MessageType>
    <Message>Preparing to unpack zip file.</Message>
    <StageName>Extract</StageName>
    <StageIndex>0</StageIndex>
    <StageCount>2</StageCount>
    <StageProgress>0</StageProgress>
    <StageTotalProgress>1</StageTotalProgress>
  </JobMessage>
   <JobMessage>
    <TimestampUtc>2014-09-08T10:18:12.7592472Z</TimestampUtc>
    <MessageType>Info</MessageType>
    <Message>Imported catalog TestCatalog</Message>
    <StageName>Import</StageName>
    <StageIndex>1</StageIndex>
    <StageCount>2</StageCount>
    <StageProgress>9900</StageProgress>
    <StageTotalProgress>10000</StageTotalProgress>
  </JobMessage>
  <JobMessage>
    <TimestampUtc>2014-09-08T10:18:12.8102795Z</TimestampUtc>
    <MessageType>Info</MessageType>
    <Message>Import successfully finished.</Message>
    <StageName>Import</StageName>
    <StageIndex>1</StageIndex>
    <StageCount>2</StageCount>
    <StageProgress>10000</StageProgress>
    <StageTotalProgress>10000</StageTotalProgress>
  </JobMessage>
  <JobMessage>
    <TimestampUtc>2014-09-08T10:18:12.8122808Z</TimestampUtc>
    <MessageType>Success</MessageType>
    <Message>Task complete.</Message>
    <StageName>Import</StageName>
    <StageIndex>1</StageIndex>
    <StageCount>2</StageCount>
    <StageProgress>10000</StageProgress>
    <StageTotalProgress>10000</StageTotalProgress>
  </JobMessage>
</ArrayOfJobMessage
>

Comments