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

Customer operations

Recommended reading 

This topic describes how to work with RESTful operations for managing customers, organizations, and contacts, when using the Episerver Service API for Episerver Commerce integrations.

See Installation and configuration, and Bulk operations for more information.

In this topic

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.

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

Get all contacts with paging [New in Service API 5.4]

get/episerverapi/commerce/customers/contact/{startIndex}/{recordsToRetrieve}

Get a specific contact 

get/episerverapi/commerce/customers/contact/{contactId}

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

Create contact 

post/episerverapi/commerce/customers/contact/{userId}

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

Update contact

put/episerverapi/commerce/customers/contact/{contactId}

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

Delete contact

delete/episerverapi/commerce/customers/contact/{contactId}

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

Organizations

Get all organizations

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

XML response type

Get a specific organization 

get/episerverapi/commerce/customers/organization/{orgId}

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

Create organization

post/episerverapi/commerce/customers/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

Update organization

put/episerverapi/commerce/customers/organization/{orgId}

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

Delete organization

delete/episerverapi/commerce/customers/organization/{orgId}

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

Related topics

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

Last updated: Apr 08, 2019

Recommended reading