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
- Retrieves a list of addresses for a customer
- Retrieves details for a single customer address
Examples
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 {
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/2025-01/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
JSON{
"customer": {
"id": "gid://shopify/Customer/544365967",
"firstName": "Bob",
"lastName": "Bobsen",
"email": "bob@example.com",
"phone": "+13125551212",
"numberOfOrders": "25",
"amountSpent": {
"amount": "8305.6",
"currencyCode": "USD"
},
"createdAt": "2005-06-15T15:57:11Z",
"updatedAt": "2005-06-16T15:57:11Z",
"note": null,
"verifiedEmail": true,
"validEmailAddress": true,
"tags": [
"Bob",
"Canadian",
"Léon",
"Noël"
],
"lifetimeDuration": "over 19 years",
"defaultAddress": {
"formattedArea": "Ottawa ON, Canada",
"address1": "123 Amoebobacterieae St"
},
"addresses": [
{
"address1": "123 Amoebobacterieae St"