Skip to main content

Customer

The Customer API lets storefront JavaScript register a customer, sign a customer in and out, and work with the signed-in customer's profile, addresses, and newsletter subscription.

All Ajax API requests should use locale-aware URLs to give visitors a consistent experience.

Authentication

Customer session. Registration, sign-in, the password reset email, the password reset, the sign-in verification code, the newsletter subscription, and the login settings are open to anonymous visitors. Every other endpoint on this page needs a signed-in customer. The session is a cookie that the browser sends automatically after a successful sign_up or sign_in. Without it, the request returns 401:

{
"errors": [
"Sign in to continue store operations."
]
}

CSRF token. Every request other than GET must carry an X-CSRF-Token header whose value is the CSRF-TOKEN cookie. The cookie is readable from JavaScript, so the examples below take it with this helper:

function getCsrfToken() {
const entry = document.cookie.split('; ').find((item) => item.startsWith('CSRF-TOKEN='));
return entry ? decodeURIComponent(entry.slice('CSRF-TOKEN='.length)) : '';
}

Without the header, the request returns 406 with {"errors":["CSRF token verify fails"]}.

Bot protection. Registration, sign-in, the password reset email, and the password reset are covered by the store's bot protection. When the server asks for a challenge, it returns 400 with {"errors":["{\"errors\":[\"empty token\"]}"]}. Submit the request again with the bot protection token in the token field and version set to v3. In a Shoplazza theme, the spz-privacy-token component fills both fields for you. In your own request, read the token from the bot protection service configured for the store (Google reCAPTCHA v3).

Request format. Endpoints on this page that send data take an application/x-www-form-urlencoded body. The examples below build it with URLSearchParams.

Create a customer account

POST /{locale}/api/customers/sign_up

Create a customer account. A successful request also starts a customer session, so the customer is signed in afterwards.

Example request

const body = new URLSearchParams({
password: 'your-password',
first_name: 'Jane',
last_name: 'Doe',
newsletter: 'true'
});

fetch(window.SHOPLAZZA.routes.root + '/api/customers/sign_up', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    emailstring

    The email address of the account.

    passwordstring

    The password of the account.

    first_namestring

    The first name of the customer.

    last_namestring

    The last name of the customer.

    newsletterboolean

    Whether the customer subscribes to marketing emails.

    tokenstring

    The bot protection token. Required when the store's bot protection asks for a challenge.

    versionstring

    The bot protection version, v3. Required together with token.

Response

  • customer object
    idstring

    ID of the customer.

    emailstring

    Email address of the customer.

    first_namestring

    First name of the customer or recipient.

    last_namestring

    Last name of the customer or recipient.

    phonestringnullable

    Phone number of the customer.

    tagsundefined[]

    Tags attached to the object.

    namestring

    Full name of the customer.

    notestringnullable

    Note attached to the object.

    contactstring

    Contact of the customer, either an email address or a phone number.

    contact_typestring

    Contact type, either email or phone.

    created_bystring
    location_idstring
    registered_atstring

    Time when the customer completed registration.

    noted_atstringnullable
    created_atstring

    Creation time, in ISO-8601 format.

    sourcestring

    Where the customer record came from.

    free_taxboolean

    Whether the customer is exempt from taxes.

    subscribedboolean

    Whether the customer is subscribed to marketing messages.

    registeredboolean

    Whether the customer has registered an account.

    customer_extra_info object

    Additional statistics about the customer.

    finished_order_countnumber

    Number of completed orders placed by the customer.

    finished_order_totalstring

    Total amount of the completed orders placed by the customer.

    countrystringnullable
    country_codestringnullable
    provincestringnullable

    Province or state of the address.

    province_codestringnullable

    Province or state code.

    currency_codestring

    Currency code of the order, for example USD.

    purchase_product_countnumber

    Number of products the customer has purchased.

    store_customer_idstring
    customer_rolestringnullable
    extstringnullable
    first_order_atstringnullable

    Time when the customer placed the first order.

    last_order_atstringnullable

    Time when the customer placed the last order.

Sign a customer in

POST /{locale}/api/customers/sign_in

Sign a customer in with an email address and a password, and start a customer session.

Example request

const body = new URLSearchParams({
password: 'your-password'
});

fetch(window.SHOPLAZZA.routes.root + '/api/customers/sign_in', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    emailstring

    The email address of the account.

    passwordstring

    The password of the account.

    tokenstring

    The bot protection token. Required when the store's bot protection asks for a challenge.

    versionstring

    The bot protection version, v3. Required together with token.

Response

  • customer object
    idstring

    ID of the customer.

    emailstring

    Email address of the customer.

    first_namestring

    First name of the customer or recipient.

    last_namestring

    Last name of the customer or recipient.

    phonestring

    Phone number of the customer.

    tagsundefined[]

    Tags attached to the object.

    namestring

    Full name of the customer.

    notestringnullable

    Note attached to the object.

    contactstring

    Contact of the customer, either an email address or a phone number.

    contact_typestring

    Contact type, either email or phone.

    created_bystring
    location_idstring
    registered_atstring

    Time when the customer completed registration.

    noted_atstringnullable
    created_atstring

    Creation time, in ISO-8601 format.

    sourcestring

    Where the customer record came from.

    free_taxstringnullable

    Whether the customer is exempt from taxes.

    subscribedboolean

    Whether the customer is subscribed to marketing messages.

    registeredboolean

    Whether the customer has registered an account.

    customer_extra_info object

    Additional statistics about the customer.

    finished_order_countnumber

    Number of completed orders placed by the customer.

    finished_order_totalstring

    Total amount of the completed orders placed by the customer.

    countrystring
    country_codestring
    provincestring

    Province or state of the address.

    province_codestring

    Province or state code.

    currency_codestring

    Currency code of the order, for example USD.

    purchase_product_countnumber

    Number of products the customer has purchased.

    store_customer_idstring
    customer_rolestringnullable
    extstringnullable
    first_order_atstring

    Time when the customer placed the first order.

    last_order_atstring

    Time when the customer placed the last order.

Sign a customer out

POST /{locale}/api/customers/sign_out

End the current customer session. Requires a signed-in customer and takes no parameters.

Example request

fetch(window.SHOPLAZZA.routes.root + '/api/customers/sign_out', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
}
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Response

    object

Send a password reset email

POST /{locale}/api/customers/password_reset_email

Send a password reset email to a customer. The email carries the verification code that PATCH /{locale}/api/customers/password_reset expects.

Example request

const body = new URLSearchParams({ email: '[email protected]' });

fetch(window.SHOPLAZZA.routes.root + '/api/customers/password_reset_email', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    emailstring

    The email address of the account.

Response

    object

Reset a customer's password

PATCH /{locale}/api/customers/password_reset

Set a new password for a customer with the verification code from the password reset email.

Example request

const body = new URLSearchParams({
code: '123456',
password: 'your-new-password',
confirm_password: 'your-new-password'
});

fetch(window.SHOPLAZZA.routes.root + '/api/customers/password_reset', {
method: 'PATCH',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    emailstring

    The email address of the account.

    codestring

    The verification code from the password reset email.

    passwordstring

    The new password.

    confirm_passwordstring

    The new password again. Must match password.

    tokenstring

    The bot protection token. Required when the store's bot protection asks for a challenge.

    versionstring

    The bot protection version, v3. Required together with token.

Response

    object

Send a sign-in verification code

POST /{locale}/api/customers/login_email

Send a sign-in verification code to a customer's email address, for flows that let a customer sign in with a code instead of a password.

Example request

const body = new URLSearchParams({ email: '[email protected]' });

fetch(window.SHOPLAZZA.routes.root + '/api/customers/login_email', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    emailstring

    The email address that receives the code.

Response

    object

Get the store's social sign-in options

GET /{locale}/api/customers/login_settings

Get the social sign-in providers the store offers on its login page. Takes no parameters. login_setting is null when the store offers none.

Example request

fetch(window.SHOPLAZZA.routes.root + '/api/customers/login_settings')
.then((response) => response.json())
.then((data) => {
// do something...
});

Response

  • login_setting object
    googleboolean

    Whether sign-in with Google is enabled.

    appleboolean

    Whether sign-in with Apple is enabled.

    facebookboolean

    Whether sign-in with Facebook is enabled.

Get the signed-in customer's profile

GET /{locale}/api/customers/show

Get the profile of the signed-in customer. Requires a signed-in customer and takes no parameters.

Example request

fetch(window.SHOPLAZZA.routes.root + '/api/customers/show')
.then((response) => response.json())
.then((data) => {
// do something...
});

Response

  • customer object
    idstring

    ID of the customer.

    emailstring

    Email address of the customer.

    first_namestring

    First name of the customer or recipient.

    last_namestring

    Last name of the customer or recipient.

    phonestring

    Phone number of the customer.

    tagsundefined[]

    Tags attached to the object.

    namestring

    Full name of the customer.

    notestringnullable

    Note attached to the object.

    contactstring

    Contact of the customer, either an email address or a phone number.

    contact_typestring

    Contact type, either email or phone.

    created_bystring
    location_idstring
    registered_atstring

    Time when the customer completed registration.

    noted_atstringnullable
    created_atstring

    Creation time, in ISO-8601 format.

    sourcestring

    Where the customer record came from.

    free_taxstringnullable

    Whether the customer is exempt from taxes.

    subscribedboolean

    Whether the customer is subscribed to marketing messages.

    registeredboolean

    Whether the customer has registered an account.

    customer_extra_info object

    Additional statistics about the customer.

    finished_order_countnumber

    Number of completed orders placed by the customer.

    finished_order_totalstring

    Total amount of the completed orders placed by the customer.

    countrystringnullable
    country_codestringnullable
    provincestringnullable

    Province or state of the address.

    province_codestringnullable

    Province or state code.

    currency_codestring

    Currency code of the order, for example USD.

    purchase_product_countnumber

    Number of products the customer has purchased.

    store_customer_idstring
    customer_rolestringnullable
    extstringnullable
    first_order_atstringnullable

    Time when the customer placed the first order.

    last_order_atstringnullable

    Time when the customer placed the last order.

Update the signed-in customer's profile

PATCH /{locale}/api/customers/update

Update the name and the email address of the signed-in customer. Requires a signed-in customer. Send email together with the name fields.

Example request

const body = new URLSearchParams({
first_name: 'Jane',
last_name: 'Doe'
});

fetch(window.SHOPLAZZA.routes.root + '/api/customers/update', {
method: 'PATCH',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    emailstring

    The email address of the account.

    first_namestring

    The first name of the customer.

    last_namestring

    The last name of the customer.

Response

  • customer object
    emailstring

    Email address of the customer.

    first_namestring

    First name of the customer or recipient.

    last_namestring

    Last name of the customer or recipient.

    phonestring

    Phone number of the customer.

    idstring

    ID of the customer.

    contact_typestring

    Contact type, either email or phone.

    contactstring

    Contact of the customer, either an email address or a phone number.

    namestring

    Full name of the customer.

    tagsundefined[]

    Tags attached to the object.

    notestringnullable

    Note attached to the object.

    created_bystring
    location_idstring
    registered_atstring

    Time when the customer completed registration.

    noted_atstringnullable
    created_atstring

    Creation time, in ISO-8601 format.

    sourcestring

    Where the customer record came from.

    free_taxstringnullable

    Whether the customer is exempt from taxes.

    subscribedboolean

    Whether the customer is subscribed to marketing messages.

    registeredboolean

    Whether the customer has registered an account.

    customer_extra_info object

    Additional statistics about the customer.

    finished_order_countnumber

    Number of completed orders placed by the customer.

    finished_order_totalstring

    Total amount of the completed orders placed by the customer.

    countrystringnullable
    country_codestringnullable
    provincestringnullable

    Province or state of the address.

    province_codestringnullable

    Province or state code.

    currency_codestring

    Currency code of the order, for example USD.

    purchase_product_countnumber

    Number of products the customer has purchased.

    store_customer_idstring
    customer_rolestringnullable
    extstringnullable
    first_order_atstringnullable

    Time when the customer placed the first order.

    last_order_atstringnullable

    Time when the customer placed the last order.

Subscribe an email address to marketing emails

POST /{locale}/api/customers/newsletters

Subscribe an email address to the store's marketing emails. Open to anonymous visitors.

Example request

const body = new URLSearchParams({ email: '[email protected]' });

fetch(window.SHOPLAZZA.routes.root + '/api/customers/newsletters', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    emailstring

    The email address to subscribe.

Response

    idstring

    ID of the customer that was subscribed.

List a customer's addresses

GET /{locale}/api/customers/addresses

List the addresses of the signed-in customer. Requires a signed-in customer.

Example request

fetch(window.SHOPLAZZA.routes.root + '/api/customers/addresses?per_page=40')
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    per_pagenumber

    The number of addresses to return.

Response

    countnumber

    Number of addresses returned.

    addresses object[]

    List of the customer addresses.

  • Array [
  • idstring

    ID of the address.

    first_namestring

    First name of the customer or recipient.

    last_namestring

    Last name of the customer or recipient.

    phonestringnullable

    Phone number associated with the address.

    emailstring

    Email address associated with the address.

    countrystring

    Country name of the address.

    country_codestring

    ISO country code of the address.

    provincestring

    Province or state of the address.

    province_codestring

    Province or state code.

    areastringnullable

    Area or district of the address.

    citystring

    City of the address.

    companystringnullable

    Company name of the address.

    zipstring

    Postal or ZIP code.

    genderstringnullable

    Gender of the recipient.

    phone_area_codestringnullable

    Area code of the phone number.

    addressstring

    Street address of the recipient.

    address1string

    Primary street address.

    is_defaultboolean

    Whether this is the customer's default address.

    created_atstring

    Creation time, in ISO-8601 format.

  • ]

Create an address

POST /{locale}/api/customers/addresses

Add an address to the signed-in customer's address book. Requires a signed-in customer. Send country and country_code together.

Example request

const body = new URLSearchParams({
first_name: 'Jane',
last_name: 'Doe',
address: '123 Main St',
address1: 'Apt 4',
city: 'Los Angeles',
province: 'California',
province_code: 'CA',
country: 'United States',
country_code: 'US',
zip: '90001',
is_default: '1'
});

fetch(window.SHOPLAZZA.routes.root + '/api/customers/addresses', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    first_namestring

    The first name of the recipient.

    last_namestring

    The last name of the recipient.

    addressstring

    The first line of the street address.

    address1string

    The second line of the street address, such as an apartment number.

    citystring

    The city.

    provincestring

    The name of the province or state.

    province_codestring

    The code of the province or state, such as CA.

    countrystring

    The name of the country, such as United States.

    country_codestring

    The two-letter code of the country, such as US.

    zipstring

    The postal code.

    emailstring

    The email address of the recipient.

    is_defaultnumber

    Whether this becomes the default address, 1 or 0.

Response

  • address object
    idstring

    ID of the address.

    first_namestring

    First name of the customer or recipient.

    last_namestring

    Last name of the customer or recipient.

    phonestringnullable

    Phone number associated with the address.

    emailstring

    Email address associated with the address.

    countrystring

    Country name of the address.

    country_codestring

    ISO country code of the address.

    provincestring

    Province or state of the address.

    province_codestring

    Province or state code.

    areastringnullable

    Area or district of the address.

    citystring

    City of the address.

    companystringnullable

    Company name of the address.

    zipstring

    Postal or ZIP code.

    genderstringnullable

    Gender of the recipient.

    phone_area_codestringnullable

    Area code of the phone number.

    addressstring

    Street address of the recipient.

    address1string

    Primary street address.

    is_defaultboolean

    Whether this is the customer's default address.

    created_atstring

    Creation time, in ISO-8601 format.

Get an address

GET /{locale}/api/customers/addresses/{address_id}

Get one address of the signed-in customer. Requires a signed-in customer.

Example request

fetch(window.SHOPLAZZA.routes.root + '/api/customers/addresses/f4892e84-0d09-4370-8144-37a21a01f2f6')
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    address_idstring

    The id of the address.

Response

  • address object
    idstring

    ID of the address.

    first_namestring

    First name of the customer or recipient.

    last_namestring

    Last name of the customer or recipient.

    phonestringnullable

    Phone number associated with the address.

    emailstring

    Email address associated with the address.

    countrystring

    Country name of the address.

    country_codestring

    ISO country code of the address.

    provincestring

    Province or state of the address.

    province_codestring

    Province or state code.

    areastringnullable

    Area or district of the address.

    citystring

    City of the address.

    companystringnullable

    Company name of the address.

    zipstring

    Postal or ZIP code.

    genderstringnullable

    Gender of the recipient.

    phone_area_codestringnullable

    Area code of the phone number.

    addressstring

    Street address of the recipient.

    address1string

    Primary street address.

    is_defaultboolean

    Whether this is the customer's default address.

    created_atstring

    Creation time, in ISO-8601 format.

Update an address

PATCH /{locale}/api/customers/addresses/{address_id}

Update one address of the signed-in customer. Requires a signed-in customer. Send country and country_code together.

Example request

const body = new URLSearchParams({
first_name: 'Jane',
last_name: 'Doe',
address: '456 Oak Ave',
city: 'Los Angeles',
province: 'California',
province_code: 'CA',
country: 'United States',
country_code: 'US',
zip: '90002'
});

fetch(window.SHOPLAZZA.routes.root + '/api/customers/addresses/f4892e84-0d09-4370-8144-37a21a01f2f6', {
method: 'PATCH',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken()
},
body: body
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    address_idstring

    The id of the address.

    first_namestring

    The first name of the recipient.

    last_namestring

    The last name of the recipient.

    addressstring

    The first line of the street address.

    citystring

    The city.

    provincestring

    The name of the province or state.

    province_codestring

    The code of the province or state, such as CA.

    countrystring

    The name of the country, such as United States.

    country_codestring

    The two-letter code of the country, such as US.

    zipstring

    The postal code.

Response

  • address object
    idstring

    ID of the address.

    first_namestring

    First name of the customer or recipient.

    last_namestring

    Last name of the customer or recipient.

    countrystring

    Country name of the address.

    country_codestring

    ISO country code of the address.

    provincestring

    Province or state of the address.

    province_codestring

    Province or state code.

    citystring

    City of the address.

    zipstring

    Postal or ZIP code.

    emailstring

    Email address associated with the address.

    genderstringnullable

    Gender of the recipient.

    phonestringnullable

    Phone number associated with the address.

    areastringnullable

    Area or district of the address.

    companystringnullable

    Company name of the address.

    phone_area_codestringnullable

    Area code of the phone number.

    addressstring

    Street address of the recipient.

    address1string

    Primary street address.

    is_defaultboolean

    Whether this is the customer's default address.

    created_atstring

    Creation time, in ISO-8601 format.

Delete an address

DELETE /{locale}/api/customers/addresses/{address_id}

Delete one address of the signed-in customer. Requires a signed-in customer.

Example request

fetch(window.SHOPLAZZA.routes.root + '/api/customers/addresses/f4892e84-0d09-4370-8144-37a21a01f2f6', {
method: 'DELETE',
headers: {
'X-CSRF-Token': getCsrfToken()
}
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    address_idstring

    The id of the address.

Response

    object

Set the default address

POST /{locale}/api/customers/addresses/{address_id}/default

Make one address the default address of the signed-in customer. Requires a signed-in customer.

Example request

fetch(window.SHOPLAZZA.routes.root + '/api/customers/addresses/f4892e84-0d09-4370-8144-37a21a01f2f6/default', {
method: 'POST',
headers: {
'X-CSRF-Token': getCsrfToken()
}
})
.then((response) => response.json())
.then((data) => {
// do something...
});

Request parameters

    address_idstring

    The id of the address.

Response

    object

Get the store's address form settings

GET /{locale}/api/customers/address_settings

Get how the store's address form is configured: how the name fields are laid out, which optional fields are shown or hidden, and which contact fields are required. Requires a signed-in customer and takes no parameters.

Example request

fetch(window.SHOPLAZZA.routes.root + '/api/customers/address_settings')
.then((response) => response.json())
.then((data) => {
// do something...
});

Response

    emailstring

    Display setting of the email field in the address form.

    namestring

    How the name fields are laid out in the address form.

    phonestring

    Display setting of the phone field in the address form.

    companystring

    Display setting of the company field in the address form, for example hidden.

    address1string

    Display setting of the street address field in the address form.

    name_requirementstring

    Which name field is required, for example last_name.

    contact_detailsstring

    How contact fields are collected in the address form.