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

Customer operations

Describes how to work with RESTful operations for managing customers, organizations, and contacts, when using the Optimizely Service API for Optimizely Commerce integrations.

Example models

public class Contact
{
  public Guid? PrimaryKeyId { get; set; }
  public Address[] Addresses { get; set; }
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public string Email { get; set; }
  public string RegistrationSource { get; set; }
 }
 
public class Address
{
  public Guid? AddressId { get; set; }
  public DateTime? Modified { get; set; }
  public string Name { get; set; }
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public string CountryName { get; set; }
  public string CountryCode { get; set; }
  public string City { get; set; }
  public string PostalCode { get; set; }
  public string Line1 { get; set; }
  public string Line2 { get; set; }
  public string RegionName { get; set; }
  public string RegionCode { get; set; }
  public string Email { get; set; }
  public bool ShippingDefault { get; set; }
  public bool BillingDefault { get; set; }
  public string DaytimePhoneNumber { get; set; }
  public string EveningPhoneNumber { get; set; }
  public string Organization { get; set; }
}
public class Organization
{
  public Guid PrimaryKeyId { get; set; }
  public IEnumerable<Address> Addresses { get; set; }
  public IEnumerable<Organization> ChildOrganizations { get; set; }
  public IEnumerable<Contact> Contacts { get; set; }
  public string OrganizationType { get; set; }
  public string OrgCustomerGroup { get; set; } 
}

Contacts

Get all contacts

📘

Note

This method only retrieves the first 1000 objects. To get more objects, see Get all contacts with paging.

GETget/episerverapi/commerce/customers/contactGet all contacts

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/customers/contact").Result.Content.ReadAsStringAsync().Result

Request and response

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));		
var result = client.GetAsync("/episerverapi/commerce/customers/contact").Result.Content.ReadAsStringAsync().Result

Response

<ArrayOfContact xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Contact>
    <PrimaryKeyId>de34525b-fff5-46ce-ba40-0cb05e54df22</PrimaryKeyId>
    <Addresses />
    <FirstName>Order</FirstName>
    <LastName>Manager</LastName>
    <Email>[email protected]</Email>
  </Contact>
  <Contact>
    <PrimaryKeyId>fe28218b-4fa9-496a-900c-678004a8f39a</PrimaryKeyId>
    <Addresses />
    <FirstName>Shipping</FirstName>
    <LastName>Manager</LastName>
    <Email>[email protected]</Email>
  </Contact>
  <Contact>
    <PrimaryKeyId>165c5742-4015-431c-a567-6853c3a0edd1</PrimaryKeyId>
    <Addresses />
    <FirstName>Receiving</FirstName>
    <LastName>Manager</LastName>
    <Email>[email protected]</Email>
  </Contact>
  <Contact>
    <PrimaryKeyId>4fcb2e02-3f88-431a-a1f0-83c4b0b51e82</PrimaryKeyId>
    <Addresses />
    &lt;FirstName>[email protected]</FirstName>
    <LastName />
    <Email />
  </Contact>
  <Contact>
    <PrimaryKeyId>24813df6-eea0-4871-aa4b-e89984eaa2a3</PrimaryKeyId>
    <Addresses />
    <FirstName>Order</FirstName>
    <LastName>Supervisor</LastName>
    <Email>[email protected]</Email>
  </Contact>
</ArrayOfContact>
GETget/episerverapi/commerce/customers/contact/{startIndex}/{recordsToRetrieve}Get all contacts with paging [New in Service API 5.4]
GETget/episerverapi/commerce/customers/contact/{contactId}Get a specific contact

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/customers/contact/{contactId}").Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));		
var result = client.GetAsync("/episerverapi/commerce/customers/contact/{contactId}").Result.Content.ReadAsStringAsync().Result

Response

<Contact>
  <PrimaryKeyId>de34525b-fff5-46ce-ba40-0cb05e54df22</PrimaryKeyId>
  <Addresses />
  <FirstName>Order</FirstName>
  <LastName>Manager</LastName>
  <Email>[email protected]</Email>
</Contact>

Create contact

POSTpost/episerverapi/commerce/customers/contact/{userId}Create contact

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/customers/contact/{userId}",
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"]) 
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
var serializer = new XmlSerializer(typeof(Contact));
var xml = String.Empty;
using (var ms = new MemoryStream())
  {
    serializer.Serialize(ms, model);
    xml = Encoding.Default.GetString(ms.ToArray());
  } 
var result = client.PostAsync("/episerverapi/commerce/customers/contact/{userId}",
  new StringContent(xml, Encoding.UTF8, "text/xml")).Result.Content.ReadAsStringAsync().Result

Response

<Contact xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <PrimaryKeyId>099e12f5-684c-4f34-a38b-cebfc8e41816</PrimaryKeyId>
  <Addresses>
    <Address>
      <AddressId>c0bc3105-7191-48e8-b921-3d557ebd4dd1</AddressId>
      <Modified>2017-10-02T08:49:57.107+02:00</Modified>
      <Name>Shipping address</Name>
      <FirstName>Customer</FirstName>
      <LastName>Sample</LastName>
      <CountryCode>US</CountryCode>
      <City>New York</City>
      <PostalCode>10012</PostalCode>
      <Line1>379 West Broadway</Line1>
      <Line2>Suite 248</Line2>
      <RegionName>New York</RegionName>
      <RegionCode>NY</RegionCode>
      <Email>[email protected]</Email>
      <ShippingDefault>true</ShippingDefault>
      <BillingDefault>false</BillingDefault>
      <DaytimePhoneNumber>(347) 261-7408</DaytimePhoneNumber>
      <EveningPhoneNumber>(347) 261-7408</EveningPhoneNumber>
    </Address>
    <Address>
      <AddressId>19245200-1045-44a5-afae-fd0bb86c279f</AddressId>
      <Modified>2017-10-02T08:49:57.203+02:00</Modified>
      <Name>Shipping address</Name>
      <FirstName>Customer</FirstName>
      <LastName>Sample</LastName>
      <CountryCode>US</CountryCode>
      <City>New York</City>
      <PostalCode>10012</PostalCode>
      <Line1>379 West Broadway</Line1>
      <Line2>Suite 248</Line2>
      <RegionName>New York</RegionName>
      <RegionCode>NY</RegionCode>
      <Email>[email protected]</Email>
      <ShippingDefault>true</ShippingDefault>
      <BillingDefault>false</BillingDefault>
      <DaytimePhoneNumber>(347) 261-7408</DaytimePhoneNumber>
      <EveningPhoneNumber>(347) 261-7408</EveningPhoneNumber>
    </Address>
  </Addresses>
  <FirstName>Customer</FirstName>
  <LastName>Sample</LastName>
  <Email>[email protected]</Email>
  <RegistrationSource>Geta.ServiceApi.Commerce integration tests</RegistrationSource>
</Contact>

Update contact

PUTput/episerverapi/commerce/customers/contact/{contactId}Update contact

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/customers/contact/{contactId}",
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
var serializer = new XmlSerializer(typeof(Contact));
var xml = String.Empty;
using (var ms = new MemoryStream())
  {
    serializer.Serialize(ms, model);
    xml = Encoding.Default.GetString(ms.ToArray());
  } 	
var result = client.PutAsync("/episerverapi/commerce/customers/contact/{contactId}",
  new StringContent(xml, Encoding.UTF8, "text/xml")).Result.Content.ReadAsStringAsync().Result

Response

200 No Content

Delete contact

DELETEdelete/episerverapi/commerce/customers/contact/{contactId}Delete contact

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/customers/contact/{contactId}").Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));	
var result = client.DeleteAsync("/episerverapi/commerce/customers/contact/{contactId}").Result.Content.ReadAsStringAsync().Result

Response

<Contact>
  <PrimaryKeyId>de34525b-fff5-46ce-ba40-0cb05e54df22</PrimaryKeyId>
  <Addresses />
  <FirstName>Order</FirstName>
  <LastName>Manager</LastName>
  <Email>[email protected]</Email>
</Contact>

Organizations

Get all organizations

GETget/episerverapi/commerce/customers/organizationGet all organizations

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/customers/organization").Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));		
var result = client.GetAsync("/episerverapi/commerce/customers/organization").Result.Content.ReadAsStringAsync().Result

Response

<Organizations>
  <Organization>
    <PrimaryKeyId>9718eb2d-8839-432d-a6f7-32cf30e5f3af</PrimaryKeyId>
    <Addresses />
   <ChildOrganizations>
      <Organization>
         <PrimaryKeyId>943a4d24-8f93-4e93-bca7-f7f227a564b1</PrimaryKeyId>
         <Addresses />
         <ChildOrganizations />
         <Contacts />
         <OrganizationType>Organization Unit</OrganizationType>
         <OrgCustomerGroup>Customer</OrgCustomerGroup>
      </Organization>
   </ChildOrganizations>   
    <Contacts />
    <OrganizationType>Organization</OrganizationType>
    <OrgCustomerGroup>Partner</OrgCustomerGroup>
 </Organization>
 <Organization>
   <PrimaryKeyId>9718eb2d-8839-432d-a6f7-f7f227a564b1</PrimaryKeyId>
   <Addresses />
   <ChildOrganizations />
   <Contacts />
    <OrganizationType>Organization Unit</OrganizationType>
    <OrgCustomerGroup>Customer</OrgCustomerGroup>
 </Organization>
</Organizations>

Get a specific organization

GETget/episerverapi/commerce/customers/organization/{orgId}Get a specific organization

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/customers/organization/{orgId}").Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));		
var result = client.GetAsync("/episerverapi/commerce/customers/organization/{orgId}").Result.Content.ReadAsStringAsync().Result

Response

<Organization>
    <PrimaryKeyId>9718eb2d-8839-432d-a6f7-32cf30e5f3af</PrimaryKeyId>
    <Addresses />
   <ChildOrganizations>
      <Organization>
         <PrimaryKeyId>943a4d24-8f93-4e93-bca7-f7f227a564b1</PrimaryKeyId>
         <Addresses />
         <ChildOrganizations />
         <Contacts />
         <OrganizationType>Organization Unit</OrganizationType>
         <OrgCustomerGroup>Customer</OrgCustomerGroup>
      </Organization>
   </ChildOrganizations>   
    <Contacts />
    <OrganizationType>Organization</OrganizationType>
    <OrgCustomerGroup>Partner</OrgCustomerGroup>
 </Organization>

Create an organization

POSTpost/episerverapi/commerce/customers/organizationCreate organization

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/customers/organization",
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
var serializer = new XmlSerializer(typeof(Organization));
var xml = String.Empty;
using (var ms = new MemoryStream())
  {
    serializer.Serialize(ms, model);
    xml = Encoding.Default.GetString(ms.ToArray());
  } 
var result = client.PostAsync("/episerverapi/commerce/customers/organization",
  new StringContent(xml, Encoding.UTF8, "text/xml")).Result.Content.ReadAsStringAsync().Result

Response

<Organization>
    <PrimaryKeyId>9718eb2d-8839-432d-a6f7-32cf30e5f3af</PrimaryKeyId>
    <Addresses />
   <ChildOrganizations>
      <Organization>
         <PrimaryKeyId>943a4d24-8f93-4e93-bca7-f7f227a564b1</PrimaryKeyId>
         <Addresses />
         <ChildOrganizations />
         <Contacts />
         <OrganizationType>Organization Unit</OrganizationType>
         <OrgCustomerGroup>Customer</OrgCustomerGroup>
      </Organization>
   </ChildOrganizations>   
    <Contacts />
    <OrganizationType>Organization</OrganizationType>
    <OrgCustomerGroup>Partner</OrgCustomerGroup>
 </Organization>

Update an organization

PUTput/episerverapi/commerce/customers/organization/{orgId}Update organization

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/customers/organization/{orgId}",
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
var serializer = new XmlSerializer(typeof(Organization));
var xml = String.Empty;
using (var ms = new MemoryStream())
  {
    serializer.Serialize(ms, model);
    xml = Encoding.Default.GetString(ms.ToArray());
  } 	
var result = client.PutAsync("/episerverapi/commerce/customers/organization",
  new StringContent(xml, Encoding.UTF8, "text/xml")).Result.Content.ReadAsStringAsync().Result

Response

200 No Content

Delete an organization

DELETEdelete/episerverapi/commerce/customers/organization/{orgId}Delete organization

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/customers/organization/{orgId}").Result.Content.ReadAsStringAsync().Result

XML response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));	
var result = client.DeleteAsync("/episerverapi/commerce/customers/organization/{orgId}").Result.Content.ReadAsStringAsync().Result

Response

<Organization>
    <PrimaryKeyId>9718eb2d-8839-432d-a6f7-32cf30e5f3af</PrimaryKeyId>
    <Addresses />
   <ChildOrganizations>
      <Organization>
         <PrimaryKeyId>943a4d24-8f93-4e93-bca7-f7f227a564b1</PrimaryKeyId>
         <Addresses />
         <ChildOrganizations />
         <Contacts />
         <OrganizationType>Organization Unit</OrganizationType>
         <OrgCustomerGroup>Customer</OrgCustomerGroup>
      </Organization>
   </ChildOrganizations>   
    <Contacts />
    <OrganizationType>Organization</OrganizationType>
    <OrgCustomerGroup>Partner</OrgCustomerGroup>
 </Organization>