Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Bulk operations

Describes how to work with bulk operations when using the Optimizely Service API, a service layer used for integration of Optimizely Commerce with external systems, such as Optimizely Product Information Management, DAM, and ERPs.

Integrations, such as with Optimizely Product Information Management, often involve the transfer of large data volumes. The Service API allows for bulk operations that can take a long time to complete.

To facilitate long-running tasks, bulk operations return a task identifier that you can use to get the status of a task and any associated messages. You can get last or aggregated status messages for the associated task identifier.

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

GETget/episerverapi/commerce/task/{taskId}/statusThis method gets the _last_status message of the associated task identifier.

JSON response type

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/task/{taskId}/status", content).Result;
  }

XML response type

C# code sample

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/{taskId}/status", content).Result;
	
  }

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

GETget/episerverapi/commerce/task/{taskId}/logThis method gets the aggregated status messages of the associated task identifier.

JSON response type

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/task/{taskId}/log", content).Result;
  }

XML response type

C# code sample

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/{taskid}/log", content).Result;
  }

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>