Customer resource
Pulling & pushing customer data is common use of the API. This section documents the Customer
resource & a few other related resources.
The Customer
resource (note: singular) stores all data relating to a customer / member of the website. Other related resources include:
- UserCustomerGroups - the relationship record between a
Customer
and a UserGroups resource, containing the group code(s) that this customer is in.- UserGroups - data about the actual groups - related to the
UserCustomerGroups
relationship record.
- UserGroups - data about the actual groups - related to the
- Order - any orders related to the customer
Customer fields
The main customer fields you may want to interact with include:
username
- the primary key for a customer.password
- a password hash for the customeremail
- email addressphone_day
- the main phone numberphone_night
- alternative phone number- Primary (billing) customer data / address fields:
b_company
- company nameb_fname
- first nameb_lname
- last nameb_address1
- address 1b_address2
- address 2b_address3
- address 3b_city
- cityb_state
- stateb_zip
- postcodeb_country
- country code
- Shipping customer data / address fields (if different):
company
- company namefname
- first namelname
- last nameaddress1
- address 1address2
- address 2address3
- address 3city
- citystate
- statezip
- postcodecountry
- country code
inactive
- is this customer inactive?discount
- an adhoc % discount to apply to this customer. This is anint
, so20
is a20%
discount.no_email
- has this user unsubscribed from all unsolicited communications?mv_shipmode
- preferred shipping mode (as per theShipping
resource)custom_data1
tocustom_data4
- these are blank fields that are not used by our software, and exist for 3rd party developers needing to store additional adhoc data against a customer. Feel free to use them - just be sure they're not being used by another integration.
Example - creating a customer
The following request could be used to create a new customer (or update an exising customer if one already existed with the same username
). We can set the new customer's groups at the same time by POST
ing to the appropriate resource specification.
POST /API/V3/Customer+UserCustomerGroups
<ResultSet>
<Customer>
<username>peter@parker.nz</username>
<password>PETERFOO123</password>
<email>peter@parker.nz</email>
<b_fname>Peter</b_fname>
<b_lname>Parker</b_lname>
<UserCustomerGroup>
<username>peter@parker.nz</username>
<group_code>dealer</group_code>
</UserCustomerGroup>
<UserCustomerGroup>
<username>peter@parker.nz</username>
<group_code>vip</group_code>
</UserCustomerGroup>
</Customer>
</ResultSet>
The password will be automatically hashed before storing in the database. Future GETs will return the hashed password.
You could look to update a customer's password by using a PUT
as follows:
PUT /API/V3/Customer/peter@parker.nz
<ResultSet>
<Customer>
<username>peter@parker.nz</username>
<b_fname>Paul</b_fname>
</Customer>
</ResultSet>
Example - Creating a customer group
Note you only have to include the entry key and the fields you wish to update.
If you need to dynamically create customer groups, you can POST
to the UserGroups resource:
POST /API/V3/UserGroups
<ResultSet>
<UserGroup>
<code>jedis</code>
<title>Jedis</title>
</UserGroup>
<UserGroup>
<code>storm-troopers</code>
<title>Storm Troopers</title>
</UserGroup>
</ResultSet>
Integrations occasionally use this approach to create a customer group for each customer in order to implement customer specific pricing (be careful that you don't have too many customers / products if implementing this or the number of entries can explode very quickly, resuting in pages with lots of price calculations slowing right down).
Related resources
UserCustomerGroups 1:M
When a Customer
has been assigned to one or more customer groups, this resource will represent the relationship between the customer and the group. If you join it into your resource specification - e.g. /API/V3/Customer+UserCustomerGroups
, it will embed a node for this resource for each group the customer is in.
Each node will contain these fields:
code
- primary key (auto increment integer)username
- the customer usernamegroup_code
- thecode
from the related UserGroups resourcesubscribed
- is the customer subscribed to this group for unsolicited communication (true
), or have they unsubscribed from this specific groupunsubscribed
.custom_data1
tocustom_data4
- these are blank fields that are not used by our software, and exist for 3rd party developers needing to store additional adhoc data against this record. Feel free to use them - just be sure they're not being used by another integration.
UserGroups 1:M
Not related directly to a customer - but to the UserCustomerGroups
entry (allowing a many:many relationship between Customer
& UserGroups
). If you need additional data about the group (e.g. its title) you can join the UserGroups
resource to the UserCustomerGroups
entry. In a resource specification this may look like: /API/V3/Customer+(UserCustomerGroups+UserGroups)
.
Key fields include:
code
- the customer group codetitle
- name / title of the groupdescription
- group descriptionsubscribable
- should a customer be able to opt-in or opt-out from this group? If so it should be public. If this group is for internal grouping only, set it to private.subscribe_text
- if this is a public group, what text should be displayed to try get the customer to subscribe to this group?parent_code
- optionally make this a 'sub-group' underneath another parent group by specifying theUserGroup
code for its parent.
Order 1:M
Order(s) that have been placed by the Customer
.
See more in the Order resource documentation.