Anchor to customer
customer
query
Returns a Customer resource by ID.
Anchor to Possible returnsPossible returns
- Anchor to CustomerCustomer•
Represents information about a customer of the shop, such as the customer's contact details, their order history, and whether they've agreed to receive marketing material by email.
Caution: Only use this data if it's required for your app's functionality. Shopify will restrict access to scopes for apps that don't have a legitimate use for the associated data.
Was this section helpful?
- Get a customer by ID
- Get a customer's name, email, and default address
- Get a metafield attached to a customer
- Get all a customer's fields and connections
- Get metafields attached to a customer
- Get pinned metafield definitions associated with a customer
- Get the email, name, and account creation date of three customers using a fragment
- Get the first five line items of the customer's last order
- Get the merge status of a customer
- Get two specific customers by their ID using aliases
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 query {6 customer(id: "gid://shopify/Customer/544365967") {7 id8 firstName9 lastName10 email11 phone12 numberOfOrders13 amountSpent {14 amount15 currencyCode16 }17 createdAt18 updatedAt19 note20 verifiedEmail21 validEmailAddress22 tags23 lifetimeDuration24 defaultAddress {25 formattedArea26 address127 }28 addresses {29 address130 }31 image {32 src33 }34 canDelete35 }36 }`,37);3839const data = await response.json();40
query {
customer(id: "gid://shopify/Customer/544365967") {
id
firstName
lastName
email
phone
numberOfOrders
amountSpent {
amount
currencyCode
}
createdAt
updatedAt
note
verifiedEmail
validEmailAddress
tags
lifetimeDuration
defaultAddress {
formattedArea
address1
}
addresses {
address1
}
image {
src
}
canDelete
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "query { customer(id: \"gid://shopify/Customer/544365967\") { id firstName lastName email phone numberOfOrders amountSpent { amount currencyCode } createdAt updatedAt note verifiedEmail validEmailAddress tags lifetimeDuration defaultAddress { formattedArea address1 } addresses { address1 } image { src } canDelete } }"
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query {
customer(id: "gid://shopify/Customer/544365967") {
id
firstName
lastName
email
phone
numberOfOrders
amountSpent {
amount
currencyCode
}
createdAt
updatedAt
note
verifiedEmail
validEmailAddress
tags
lifetimeDuration
defaultAddress {
formattedArea
address1
}
addresses {
address1
}
image {
src
}
canDelete
}
}`,
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: `query {
customer(id: "gid://shopify/Customer/544365967") {
id
firstName
lastName
email
phone
numberOfOrders
amountSpent {
amount
currencyCode
}
createdAt
updatedAt
note
verifiedEmail
validEmailAddress
tags
lifetimeDuration
defaultAddress {
formattedArea
address1
}
addresses {
address1
}
image {
src
}
canDelete
}
}`,
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
query {
customer(id: "gid://shopify/Customer/544365967") {
id
firstName
lastName
email
phone
numberOfOrders
amountSpent {
amount
currencyCode
}
createdAt
updatedAt
note
verifiedEmail
validEmailAddress
tags
lifetimeDuration
defaultAddress {
formattedArea
address1
}
addresses {
address1
}
image {
src
}
canDelete
}
}
QUERY
response = client.query(query: query)
Response
JSON1{2 "customer": {3 "id": "gid://shopify/Customer/544365967",4 "firstName": "Bob",5 "lastName": "Bobsen",6 "email": "bob@example.com",7 "phone": "+13125551212",8 "numberOfOrders": "25",9 "amountSpent": {10 "amount": "8305.6",11 "currencyCode": "USD"12 },13 "createdAt": "2005-06-15T15:57:11Z",14 "updatedAt": "2005-06-16T15:57:11Z",15 "note": null,16 "verifiedEmail": true,17 "validEmailAddress": true,18 "tags": [19 "Bob",20 "Canadian",21 "Léon",22 "Noël"23 ],24 "lifetimeDuration": "over 19 years",25 "defaultAddress": {26 "formattedArea": "Ottawa ON, Canada",27 "address1": "123 Amoebobacterieae St"28 },29 "addresses": [30 {31 "address1": "123 Amoebobacterieae St"32 }33 ],34 "image": {35 "src": "https://cdn.shopify.com/proxy/d02a582792c73c48b4b62a95f42bcbf6eff91c5d232efb2057ca4c41005e4728/www.gravatar.com/avatar/4b9bb80620f03eb3719e0a061c14283d.jpg?s=2048&d=https%3A%2F%2Fcdn.shopify.com%2Fshopifycloud%2Fshopify%2Fassets%2Fadmin%2Fcustomers%2Fpolaris%2Favatar-2-a0ee6e3fb3ae515b66b68388b265e5bd1e90646c4c72d59170518f45351e668b.png"36 },37 "canDelete": false38 }39}