Anchor to customerByIdentifiercustomer
customerByIdentifier
query
Requires access scope.
Return a customer by an identifier.
Anchor to Arguments
Arguments
- Anchor to identifieridentifier•Customer
Identifier requiredInput! The identifier of the customer.
Was this section helpful?
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?
- Find a customer by custom id
- Find a customer by email address
- Find a customer by phone number
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query($identifier: CustomerIdentifierInput!) {
customer: customerByIdentifier(identifier: $identifier) {
id
amountSpent {
amount
currencyCode
}
}
}`,
{
variables: {
"identifier": {
"customId": {
"namespace": "custom",
"key": "id",
"value": "16a3a6dd"
}
}
},
},
);
const data = await response.json();
query($identifier: CustomerIdentifierInput!) {
customer: customerByIdentifier(identifier: $identifier) {
id
amountSpent {
amount
currencyCode
}
}
}
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($identifier: CustomerIdentifierInput!) { customer: customerByIdentifier(identifier: $identifier) { id amountSpent { amount currencyCode } } }",
"variables": {
"identifier": {
"customId": {
"namespace": "custom",
"key": "id",
"value": "16a3a6dd"
}
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query($identifier: CustomerIdentifierInput!) {
customer: customerByIdentifier(identifier: $identifier) {
id
amountSpent {
amount
currencyCode
}
}
}`,
{
variables: {
"identifier": {
"customId": {
"namespace": "custom",
"key": "id",
"value": "16a3a6dd"
}
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `query($identifier: CustomerIdentifierInput!) {
customer: customerByIdentifier(identifier: $identifier) {
id
amountSpent {
amount
currencyCode
}
}
}`,
"variables": {
"identifier": {
"customId": {
"namespace": "custom",
"key": "id",
"value": "16a3a6dd"
}
}
},
},
});
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($identifier: CustomerIdentifierInput!) {
customer: customerByIdentifier(identifier: $identifier) {
id
amountSpent {
amount
currencyCode
}
}
}
QUERY
variables = {
"identifier": {
"customId": {
"namespace": "custom",
"key": "id",
"value": "16a3a6dd"
}
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"identifier": {
"customId": {
"namespace": "custom",
"key": "id",
"value": "16a3a6dd"
}
}
}
Response
JSON{
"customer": {
"id": "gid://shopify/Customer/544365967",
"amountSpent": {
"amount": "8305.6",
"currencyCode": "USD"
}
}
}