An object representing a customer.
Property | Type | Description |
---|---|---|
uid | integer | The unique identifier of the customer. |
changed | string | Date and time of when the customer was last modified. |
approved | boolean | Whether the customer is permitted to log in to the shop. |
created | string | Date and time of when the customer was created. |
language | string | Preferred language for the customer. |
groups | array | The customer groups in which the customer exists as an array of Customergroup objects. Accessible to administrators only. |
address | Address | Invoice address of the customer. See Address below. |
deliveryAddress | DeliveryAddress | Delivery address of the customer. See DeliveryAddress below. |
custom | object | References to any additional details requested by the shop and provided by the customer at checkout, e.g. "desired delivery date", as a list of objects. |
info | Info | An object containing customer information. See Info below. |
Property | Type | Description |
---|---|---|
company | string | Name of the company. Will return null if the customer is not a company. |
firstName | string | First name of the customer. |
lastName | string | Last name of the customer. |
address | string | Address line 1 of the customer. |
address2 | string | Address line 2 of the customer. |
postcode | string | Postcode / ZIP code of the customer. |
town | string | Post town of the customer. |
country | string | Country of the customer as an ISO 3166-1 alpha-2 code, e.g. "SE" (Sweden). |
state | string | State or province of the customer as a two-letter code, e.g. "AL" (Alabama), if any. |
phoneDay | string | Daytime phone number of the customer. |
phoneNight | string | Evening phone number of the customer. |
phoneMobile | string | Mobile phone number of the customer. |
Property | Type | Description |
---|---|---|
copyAddress | boolean | Whether delivery address is copied from the address. |
company | string | Delivery company name, if any. |
name | string | Delivery first name and last name |
address | string | Delivery address line 1. |
address2 | string | Delivery address line 2 |
postcode | string | Delivery postcode / ZIP code |
town | string | Delivery city/town |
country | string | Delivery countryas an ISO 3166-1 alpha-2 code, e.g. "SE" (Sweden). |
state | string | Delivery state or province as a two-letter code, e.g. "AL" (Alabama), if any. |
phone | string | Delivery phone number |
Property | Type | Description |
---|---|---|
type | string | Customer type: "business" or "individual" . |
nin | string | National identification number (or equivalent) or organization number (or equivalent) of the customer. |
string | Email address of the customer. | |
username | string | Username of the customer. |
vatNumber | string | Value-added tax number of the customer. |
customerNumber | string | An optional identifier of the customer modifiable by an adminstrator. May contain letters, hyphens, numbers and other characters. |
newsletter | string | Whether the customer shall receive newsletters from the shop. |
note | string | Shop's note of the customer, e.g. "Life-time guarantee on all items" . Accessible to administrators only. |
Changes the password for a logged-in customer. This method will update a customer's password if given the correct old password and a valid new password. All subsequent logins will be required to use the new password.
Parameter | Description |
---|---|
oldpassword | The old password. |
newpassword | The new password. |
Code | Message | Description |
---|---|---|
3004 | Invalid password | The new password is invalid. |
. | Invalid login | The old password is invalid. |
. | Forbidden | The customer is not logged in. |
Customer.changePassword("foobarpass", "barfoopass")
Confirms a membership. The customer needs to run signup beforehand to obtain both the hash and the activation code sent to their email address. After a successful request to this method, the new customer can use login to access their account.
Parameter | Description |
---|---|
The email address to which the activation code was sent. | |
hash | The hash as returned by signup. |
code | The activation code included in the confirmation email. |
Code | Message | Description |
---|---|---|
3003 | Bad signup code | The activation code included in the email is invalid. |
3006 | Confirmation failed | The confirmation failed because there is no pending customer with the given email. |
Customer.confirmSignup("foobar@example.com", "7037807198c22a7d2b0807371d763779a84fdfcf", "03d302c9a24f67de")
Takes a filter object and returns the number of customers found, as an integer.
A filter object specifying which customers to count. See Filter objects on the page List selection.
The request below returns the number of customers created since 1 January 2019.
Customer.count({
"/created": {
"min": "2019-01-01T00:00:00Z"
}
})
Creates a new customer. This is shorthand for set with uid null
.
Parameter | Description |
---|---|
patch | An object containing the properties and values to set for the new customer. |
query | A query specifying what to return after a successful create (optional). See Query language. |
Permanently delete a customer.
Parameter | Description |
---|---|
uid | The unique identifier of a customer. |
Customer.delete(9876540)
Fetches information about a customer.
Parameter | Description |
---|---|
uid | The unique identifier of a customer. |
query | Which info to return. See Query language. |
Customer.get(123456, [
"uid",
"groups",
"address"
])
Fetches the JSON Schema which can be used for client-side validation.
The unique identifier of an existing customer or null
for a new customer.
Returns an array of objects representing customers.
Parameter | Description |
---|---|
query | A query object specifying what to fetch from each customer. This is the same as for get. See Query language. |
selection | A list-selection object specifying which customers to fetch. See List selection. |
These orderings are available:
The following request returns the company name, email and unique identifier of all the customers created since 1 January 2019, sorted by company:
Customer.list({
"uid": true,
"info": {
"email": true
},
"address": {
"company": true
}
}, {
"filters": {
"/created": {
"min": "2019-01-01T00:00:00Z"
}
},
"sort": "company"
})
Logs in a customer to the shop. A session is needed before login can be attempted.
Parameter | Description |
---|---|
username | Username for the customer account. |
password | Password for the customer account. |
query | A query specifying what to return after a successful login (optional). See Query language. |
Code | Message | Description |
---|---|---|
3001 | Login failure | If either the username or password is incorrect. |
1008 | Session missing | If no session is supplied in the context. |
If the login is successful, the return value will be an empty object. If a query is provided, however, then the return value will be an object with properties specified in the query.
Customer.login("foo", "foobarpass")
With a query:
Customer.login("foo", "foobarpass", [
"uid"
])
Logs out the customer. A session is required for logging out. If no user is logged in when calling this method, then nothing will happen.
Code | Message | Description |
---|---|---|
1008 | Session missing | If no session is supplied in the context. |
Customer.logout()
Subscribes a customer to the webshop's newsletter.
The email address of the customer, as a string. Or first name, last name and email address of the customer as strings.
Customer.newsletterSubscribe("email@example.com")
With first name and last name:
Customer.newsletterSubscribe("Foo", "Bar", "email@example.com")
Unsubscribes a customer from the webshop's newsletter.
The email address of the customer, as a string.
If the request is successful, the return value will be null
.
Code | Message | Description |
---|---|---|
1006 | Forbidden | The request is forbidden. To proceed, you need to either log in or use a persistent authentication token. |
Customer.newsletterUnsubscribe("email@example.com")
Fetches a normalized version of the patch. Uses the same parameters as set and validate. While set also normalizes the patch, before storing, normalize only returns the normalized patch. For all properties with number types, integers or floating-point values in strings are converted to number literals. A normalization error is thrown when we are unable to convert a string to a number literal.
Parameter | Description |
---|---|
uid | The unique identifier of a customer or null to create a new customer. |
patch | An object containing the properties and values to normalize. |
Customer.normalize(123456, {
"groups": [
"1"
]
})
Requests a password reset for a customer. This method will return a hash and send an email to the customer containing a reset code. These two values can then be used to reset the customer's password using resetPassword.
The username or email of the customer.
The hash to use with the reset code.
Customer.requestPasswordReset("foobar@example.com")
Resets the password. The customer needs to run requestPasswordReset beforehand to obtain both the hash and the reset code sent to their email address. After a successful reset, the customer should be able to use login with their new password.
Parameter | Description |
---|---|
username | The username of the customer. |
hash | The hash as returned by requestPasswordReset. |
code | The reset code as sent to the customer's email address. |
newpassword | The customer's new password. |
Code | Message | Description |
---|---|---|
3002 | Bad reset code | The reset code provided is invalid. |
If the request is successful, the return value will be null
.
Customer.resetPassword("foo", "ab7911513debc7015ad50429a8159771458b24ce", "99875c5ebd8a35ae", "barfoopass")
Creates or updates a customer.
Parameter | Description |
---|---|
uid | The unique identifier of a customer or null to create a new customer. |
patch | An object containing the properties and values to set for the customer. |
query | A query specifying what to return after a successful set (optional). See Query language. |
The following request updates the email-address record for the customer with the unique identifier 9876543
and returns the email, company name and unique identifier.
Customer.set(9876543, {
"info": {
"email": "libre.software@example.com"
}
}, {
"uid": true,
"info": {
"email": true
},
"address": {
"company": true
}
})
Validates the data to be set. The performed validation is the same as in set; it validates the resulting object and includes all the required properties. However, nothing is saved.
Parameter | Description |
---|---|
uid | The unique identifier of an existing customer or null . |
patch | An object containing the properties and values to set before validating. |
An array of validation-error objects, each containing the keys pointer
(a property referenced using a JSON Pointer) and message
(a readable text in the language of the context). An empty array is returned if there are no validation errors.