Customers: list and search with cursor pagination, exact-email lookup, fetch, create and update. Needs read_customers / write_customers; customer names, emails and addresses are protected customer data, so the app needs Shopify's approval for those fields.

Values

CUSTOMER_FIELDS

CUSTOMER_FIELDS: Str "id firstName lastName displayName state tags note createdAt updatedAt\ndefaultEmailAddress { emailAddress marketingState }\ndefaultPhoneNumber { phoneNumber }\nnumberOfOrders\namountSpent { amount currencyCode }"

Functions

collect-customers

fn (options: Map, max-items: Int): Vec
fn (options: Map, max-items: Int, opts: Map): Vec

Follow cursors and return up to max-items customers (a Vec of nodes). Options as in list-customers.

Example

customers ::shopify::customers/collect-customers({query: "tag:vip"}, 500)
length(customers)

create-customer

fn (customer: Map): Map
fn (customer: Map, opts: Map): Map

Create a customer (customerCreate) from a CustomerInput: email, phone, firstName, lastName, tags, note, addresses, metafields, ... Set marketing consent separately with customerEmailMarketingConsentUpdate via graphql.

Example

c ::shopify::customers/create-customer({email: "ada@example.com", firstName: "Ada", tags: ["vip"]})

email-query

fn (email: Str): Str

The search query for an exact email match, with the value quoted so operators in it can't widen the search. Exposed for testing.

Example

::shopify::customers/email-query("ada@example.com")  // "email:\"ada@example.com\""

find-customer-by-email

fn (email: Str): Map?
fn (email: Str, opts: Map): Map?

Find a customer by exact email. Returns the customer or null.

Example

customer ::shopify::customers/find-customer-by-email("ada@example.com")
if(is-null(customer), "no match", customer.id)

get-customer

fn (id: Str): Map?
fn (id: Str, opts: Map): Map?

One customer by GraphQL id, with the default address. Returns null when not found.

Example

customer ::shopify::customers/get-customer("gid://shopify/Customer/7")
customer.email

list-customers

fn (): Map
fn (options: Map): Map
fn (options: Map, opts: Map): Map

One page of customers. Options: first (default 50, max 250), after, query (e.g. "country:canada orders_count:>5"), sortKey (NAME, CREATED_AT, UPDATED_AT, ...), reverse. Returns {nodes, pageInfo}.

Example

page ::shopify::customers/list-customers({first: 25, query: "country:canada", sortKey: "UPDATED_AT"})
map(page.nodes, %.email)
page.pageInfo.endCursor

search-customers

fn (search-query: Str): Map
fn (search-query: Str, options: Map): Map
fn (search-query: Str, options: Map, opts: Map): Map

One page of customers matching Shopify's customer search syntax. Options as in list-customers.

Example

page ::shopify::customers/search-customers("orders_count:>5", {first: 10})
map(page.nodes, %.id)

update-customer

fn (customer: Map): Map
fn (customer: Map, opts: Map): Map

Update a customer (customerUpdate) from a CustomerInput that includes the customer id and the fields to change.

Example

::shopify::customers/update-customer({id: "gid://shopify/Customer/7", tags: ["vip"], note: "Prefers phone."})