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

Carts

Recommended reading 

This topic describes how to work with RESTful operations for carts in the Optimizely Service API.

In this topic

Example models

public class PropertyItem
  {
    public string Key   { get; set;   }
    public string Value   { get; set;   }
  }

public class Discount
  {
    public int DiscountId   { get; set;   }
    public decimal DiscountAmount   { get; set;   }
    public string DiscountCode   { get; set;   }
    public string DiscountName   { get; set;   }
    public string DisplayMessage   { get; set;   }
    public decimal DiscountValue   { get; set;   }
  }

public class Shipment 
  {
    public Discount[] Discounts   { get; set;   }
    public int ShipmentId   { get; set;   }
    public Guid ShippingMethodId   { get; set;   }
    public string ShippingMethodName   { get; set;   }
    public decimal ShippingTax   { get; set;   }
    public string ShippingAddressId   { get; set;   }
    public string ShipmentTrackingNumber   { get; set;   }
    public decimal ShippingDiscountAmount   { get; set;   }
    public decimal ShippingSubTotal   { get; set;   }
    public decimal ShippingTotal   { get; set;   }
    public string Status   { get; set;   }
    public string PrevStatus   { get; set;   }
    public int? PickListId   { get; set;   }
    public decimal SubTotal   { get; set;   }
    public string WarehouseCode   { get; set;   }
    public LineItem[] LineItems   { get; set;   }
    public List<PropertyItem> Properties   { get; set;   }
  }

public class OrderForm 
  {
    public Shipment[] Shipments   { get; set;   }
    public LineItem[] LineItems   { get; set;   }
    public Discount[] Discounts   { get; set;   }
    public string ReturnComment   { get; set;   }
    public string ReturnType   { get; set;   }
    public string ReturnAuthCode   { get; set;   }
    public int OrderFormId   { get; set;   }
    public string Name   { get; set;   }
    public string BillingAddressId   { get; set;   }
    public decimal ShippingTotal   { get; set;   }
    public decimal HandlingTotal   { get; set;   }
    public decimal TaxTotal   { get; set;   }
    public decimal DiscountAmount   { get; set;   }
    public decimal SubTotal   { get; set;   }
    public decimal Total   { get; set;   }
    public string Status   { get; set;   }
    public string RmaNumber   { get; set;   }
    public decimal AuthorizedPaymentTotal   { get; set;   }
    public decimal CapturedPaymentTotal   { get; set;   }
    public List<PropertyItem> Properties   { get; set;   }
  }

public class OrderNote
  {
    public int? OrderNoteId   { get; set;   }
    public DateTime Created   { get; set;   }
    public Guid CustomerId   { get; set;   }
    public string Detail   { get; set;   }
    public string Title   { get; set;   }
    public string Type   { get; set;   }
    public int? LineItemId   { get; set;   }
  }

public class LineItem
  {
    public int LineItemId   { get; set;   }
    public string Code   { get; set;   }
    public string DisplayName   { get; set;   }
    public decimal PlacedPrice   { get; set;   }
    public decimal ExtendedPrice   { get; set;   }
    public decimal DiscountedPrice   { get; set;   }
    public decimal Quantity   { get; set;   }
    public decimal ReturnQuantity   { get; set;   }
    public string InventoryTrackingStatus   { get; set;   }
    public bool IsInventoryAllocated   { get; set;   }
    public bool IsGift   { get; set;   }
  }

public class OrderAddress
  {
    public int OrderGroupAddressId   { get; set;   }
    public string Name   { get; set;   }
    public string FirstName   { get; set;   }
    public string LastName   { get; set;   }
    public string Organization   { get; set;   }
    public string Line1   { get; set;   }
    public string Line2   { get; set;   }
    public string City   { get; set;   }
    public string State   { get; set;   }
    public string CountryCode   { get; set;   }
    public string CountryName   { get; set;   }
    public string PostalCode   { get; set;   }
    public string RegionCode   { get; set;   }
    public string RegionName   { get; set;   }
    public string DaytimePhoneNumber   { get; set;   }
    public string EveningPhoneNumber   { get; set;   }
    public string FaxNumber   { get; set;   }
    public string Email   { get; set;   }
  }

public class Cart
  {
    public string AddressId   { get; set;   }
    public Guid AffiliateId   { get; set;   }
    public string BillingCurrency   { get; set;   }
    public Guid CustomerId   { get; set;   }
    public string CustomerName   { get; set;   }
    public decimal HandlingTotal   { get; set;   }
    public Guid InstanceId   { get; set;   }
    public string MarketId   { get; set;   }
    public string Name   { get; set;   }
    public OrderAddress[] OrderAddresses   { get; set;   }
    public OrderForm[] OrderForms   { get; set;   }
    public int OrderGroupId   { get; set;   }
    public OrderNote[] OrderNotes   { get; set;   }
    public string Owner   { get; set;   }
    public string OwnerOrg   { get; set;   }
    public string ProviderId   { get; set;   }
    public decimal ShippingTotal   { get; set;   }
    public string Status   { get; set;   }
    public decimal SubTotal   { get; set;   }
    public decimal TaxTotal   { get; set;   }
    public decimal Total   { get; set;   }
    public DateTime Modified   { get; set;   }
    public DateTime Created   { get; set;   }
    public List<PropertyItem> Properties   { get; set;   }
  }

Get carts by name and customerid 

Gets a cart for a specific customer in a specific market, if market ID is provided.

get/episerverapi/commerce/carts/{customerId}/{cartName}/{marketId}
get/episerverapi/commerce/carts/{customerId}/{cartName}

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);		
var result = client.GetAsync("/episerverapi/commerce/carts/{customerId}/{name}").Result.Content.ReadAsStringAsync().Result

XML response type

Search carts 

get/episerverapi/commerce/carts/search/{start}/{maxCount}

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);		
var result = client.GetAsync("/episerverapi/commerce/carts/search/{start}/{maxCount}").Result.Content.ReadAsStringAsync().Result

XML response type

Create cart 

post/episerverapi/commerce/carts

JSON response type

C# code sample

var json = JsonConvert.SerializeObject(model);
var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);		
var result = client.PostAsync("/episerverapi/commerce/carts", new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

Update cart 

put/episerverapi/commerce/carts/{cartId}

JSON response type

C# code sample

var json = JsonConvert.SerializeObject(model);
var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);		
var result = client.PutAsync("/episerverapi/commerce/carts/{cartId}", new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

Delete cart

delete/episerverapi/commerce/carts/{customerId}/{cartName}

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);		
var result = client.DeleteAsync("/episerverapi/commerce/carts/{customername}/{name}").Result.Content.ReadAsStringAsync().Result

XML response type

Related topics

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

Last updated: Oct 04, 2017

Recommended reading