# Customer - admin-graphql - OBJECT Version: 2024-04 ## Description 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](https://shopify.dev/api/usage/access-scopes) for apps that don't have a legitimate use for the associated data. ### Access Scopes `read_customers` access scope. ## Fields * [addresses](/docs/api/admin-graphql/2024-04/objects/MailingAddress): MailingAddress! - A list of addresses associated with the customer. * [amountSpent](/docs/api/admin-graphql/2024-04/objects/MoneyV2): MoneyV2! - The total amount that the customer has spent on orders in their lifetime. * [canDelete](/docs/api/admin-graphql/2024-04/scalars/Boolean): Boolean! - Whether the merchant can delete the customer from their store. A customer can be deleted from a store only if they haven't yet made an order. After a customer makes an order, they can't be deleted from a store. * [companyContactProfiles](/docs/api/admin-graphql/2024-04/objects/CompanyContact): CompanyContact! - A list of the customer's company contact profiles. * [createdAt](/docs/api/admin-graphql/2024-04/scalars/DateTime): DateTime! - The date and time when the customer was added to the store. * [defaultAddress](/docs/api/admin-graphql/2024-04/objects/MailingAddress): MailingAddress - The default address associated with the customer. * [displayName](/docs/api/admin-graphql/2024-04/scalars/String): String! - The full name of the customer, based on the values for first_name and last_name. If the first_name and last_name are not available, then this falls back to the customer's email address, and if that is not available, the customer's phone number. * [email](/docs/api/admin-graphql/2024-04/scalars/String): String - The customer's email address. * [emailMarketingConsent](/docs/api/admin-graphql/2024-04/objects/CustomerEmailMarketingConsentState): CustomerEmailMarketingConsentState - The current email marketing state for the customer. If the customer doesn't have an email address, then this property is `null`. * [firstName](/docs/api/admin-graphql/2024-04/scalars/String): String - The customer's first name. * [hasTimelineComment](/docs/api/admin-graphql/2024-04/scalars/Boolean): Boolean! - Whether the merchant has added timeline comments about the customer on the customer's page. * [id](/docs/api/admin-graphql/2024-04/scalars/ID): ID! - A globally-unique ID. * [image](/docs/api/admin-graphql/2024-04/objects/Image): Image! - The image associated with the customer. * [lastName](/docs/api/admin-graphql/2024-04/scalars/String): String - The customer's last name. * [lastOrder](/docs/api/admin-graphql/2024-04/objects/Order): Order - The customer's last order. * [legacyResourceId](/docs/api/admin-graphql/2024-04/scalars/UnsignedInt64): UnsignedInt64! - The ID of the corresponding resource in the REST Admin API. * [lifetimeDuration](/docs/api/admin-graphql/2024-04/scalars/String): String! - The amount of time since the customer was first added to the store. Example: 'about 12 years'. * [locale](/docs/api/admin-graphql/2024-04/scalars/String): String! - The customer's locale. * [market](/docs/api/admin-graphql/2024-04/objects/Market): Market - The market that includes the customer’s default address. * [mergeable](/docs/api/admin-graphql/2024-04/objects/CustomerMergeable): CustomerMergeable! - Whether the customer can be merged with another customer. * [metafield](/docs/api/admin-graphql/2024-04/objects/Metafield): Metafield - A [custom field](https://shopify.dev/docs/apps/build/custom-data), including its `namespace` and `key`, that's associated with a Shopify resource for the purposes of adding and storing additional information. * [multipassIdentifier](/docs/api/admin-graphql/2024-04/scalars/String): String - A unique identifier for the customer that's used with Multipass login. * [note](/docs/api/admin-graphql/2024-04/scalars/String): String - A note about the customer. * [numberOfOrders](/docs/api/admin-graphql/2024-04/scalars/UnsignedInt64): UnsignedInt64! - The number of orders that the customer has made at the store in their lifetime. * [phone](/docs/api/admin-graphql/2024-04/scalars/String): String - The customer's phone number. * [privateMetafield](/docs/api/admin-graphql/2024-04/objects/PrivateMetafield): PrivateMetafield - Returns a private metafield by namespace and key that belongs to the resource. * [productSubscriberStatus](/docs/api/admin-graphql/2024-04/enums/CustomerProductSubscriberStatus): CustomerProductSubscriberStatus! - Possible subscriber states of a customer defined by their subscription contracts. * [smsMarketingConsent](/docs/api/admin-graphql/2024-04/objects/CustomerSmsMarketingConsentState): CustomerSmsMarketingConsentState - The current SMS marketing state for the customer's phone number. If the customer does not have a phone number, then this property is `null`. * [state](/docs/api/admin-graphql/2024-04/enums/CustomerState): CustomerState! - The state of the customer's account with the shop. Please note that this only meaningful when Classic Customer Accounts is active. * [statistics](/docs/api/admin-graphql/2024-04/objects/CustomerStatistics): CustomerStatistics! - The statistics for a given customer. * [tags](/docs/api/admin-graphql/2024-04/scalars/String): String! - A comma separated list of tags that have been added to the customer. * [taxExempt](/docs/api/admin-graphql/2024-04/scalars/Boolean): Boolean! - Whether the customer is exempt from being charged taxes on their orders. * [taxExemptions](/docs/api/admin-graphql/2024-04/enums/TaxExemption): TaxExemption! - The list of tax exemptions applied to the customer. * [unsubscribeUrl](/docs/api/admin-graphql/2024-04/scalars/URL): URL! - The URL to unsubscribe the customer from the mailing list. * [updatedAt](/docs/api/admin-graphql/2024-04/scalars/DateTime): DateTime! - The date and time when the customer was last updated. * [validEmailAddress](/docs/api/admin-graphql/2024-04/scalars/Boolean): Boolean! - Whether the email address is formatted correctly. Returns `true` when the email is formatted correctly and belongs to an existing domain. This doesn't guarantee that the email address actually exists. * [verifiedEmail](/docs/api/admin-graphql/2024-04/scalars/Boolean): Boolean! - Whether the customer has verified their email address. Defaults to `true` if the customer is created through the Shopify admin or API. ## Connections * [events](/docs/api/admin-graphql/2024-04/connections/EventConnection): EventConnection! * [metafieldDefinitions](/docs/api/admin-graphql/2024-04/connections/MetafieldDefinitionConnection): MetafieldDefinitionConnection! * [metafields](/docs/api/admin-graphql/2024-04/connections/MetafieldConnection): MetafieldConnection! * [orders](/docs/api/admin-graphql/2024-04/connections/OrderConnection): OrderConnection! * [paymentMethods](/docs/api/admin-graphql/2024-04/connections/CustomerPaymentMethodConnection): CustomerPaymentMethodConnection! * [privateMetafields](/docs/api/admin-graphql/2024-04/connections/PrivateMetafieldConnection): PrivateMetafieldConnection! * [subscriptionContracts](/docs/api/admin-graphql/2024-04/connections/SubscriptionContractConnection): SubscriptionContractConnection! ## Related queries * [customer](/docs/api/admin-graphql/2024-04/queries/customer) Returns a Customer resource by ID. * [customers](/docs/api/admin-graphql/2024-04/queries/customers) Returns a list of customers. ## Related mutations * [customerAddTaxExemptions](/docs/api/admin-graphql/2024-04/mutations/customerAddTaxExemptions) Add tax exemptions for the customer. * [customerCreate](/docs/api/admin-graphql/2024-04/mutations/customerCreate) Create a new customer. As of API version 2022-10, apps using protected customer data must meet the protected customer data [requirements](https://shopify.dev/apps/store/data-protection/protected-customer-data). * [customerEmailMarketingConsentUpdate](/docs/api/admin-graphql/2024-04/mutations/customerEmailMarketingConsentUpdate) Update a customer's email marketing information information. * [customerPaymentMethodSendUpdateEmail](/docs/api/admin-graphql/2024-04/mutations/customerPaymentMethodSendUpdateEmail) Sends a link to the customer so they can update a specific payment method. * [customerRemoveTaxExemptions](/docs/api/admin-graphql/2024-04/mutations/customerRemoveTaxExemptions) Remove tax exemptions from a customer. * [customerReplaceTaxExemptions](/docs/api/admin-graphql/2024-04/mutations/customerReplaceTaxExemptions) Replace tax exemptions for a customer. * [customerSmsMarketingConsentUpdate](/docs/api/admin-graphql/2024-04/mutations/customerSmsMarketingConsentUpdate) Update a customer's SMS marketing consent information. * [customerUpdateDefaultAddress](/docs/api/admin-graphql/2024-04/mutations/customerUpdateDefaultAddress) Updates a customer's default address. * [customerUpdate](/docs/api/admin-graphql/2024-04/mutations/customerUpdate) Update a customer's attributes. As of API version 2022-10, apps using protected customer data must meet the protected customer data [requirements](https://shopify.dev/apps/store/data-protection/protected-customer-data). ## Related Unions * [CommentEventEmbed](/docs/api/admin-graphql/2024-04/unions/CommentEventEmbed) The main embed of a comment event. * [MetafieldReference](/docs/api/admin-graphql/2024-04/unions/MetafieldReference) The resource referenced by the metafield value. * [MetafieldReferencer](/docs/api/admin-graphql/2024-04/unions/MetafieldReferencer) Types of resources that may use metafields to reference other resources. * [PurchasingEntity](/docs/api/admin-graphql/2024-04/unions/PurchasingEntity) Represents information about the purchasing entity for the order or draft order. ## Examples ### Get a customer by ID Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"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 } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n id\n firstName\n lastName\n email\n phone\n numberOfOrders\n amountSpent {\n amount\n currencyCode\n }\n createdAt\n updatedAt\n note\n verifiedEmail\n validEmailAddress\n tags\n lifetimeDuration\n defaultAddress {\n formattedArea\n address1\n }\n addresses {\n address1\n }\n image {\n src\n }\n canDelete\n }\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n id\n firstName\n lastName\n email\n phone\n numberOfOrders\n amountSpent {\n amount\n currencyCode\n }\n createdAt\n updatedAt\n note\n verifiedEmail\n validEmailAddress\n tags\n lifetimeDuration\n defaultAddress {\n formattedArea\n address1\n }\n addresses {\n address1\n }\n image {\n src\n }\n canDelete\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n id\n firstName\n lastName\n email\n phone\n numberOfOrders\n amountSpent {\n amount\n currencyCode\n }\n createdAt\n updatedAt\n note\n verifiedEmail\n validEmailAddress\n tags\n lifetimeDuration\n defaultAddress {\n formattedArea\n address1\n }\n addresses {\n address1\n }\n image {\n src\n }\n canDelete\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n id\n firstName\n lastName\n email\n phone\n numberOfOrders\n amountSpent {\n amount\n currencyCode\n }\n createdAt\n updatedAt\n note\n verifiedEmail\n validEmailAddress\n tags\n lifetimeDuration\n defaultAddress {\n formattedArea\n address1\n }\n addresses {\n address1\n }\n image {\n src\n }\n canDelete\n }\n}" #### Graphql Input null #### Graphql Response { "data": { "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" } ], "image": { "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" }, "canDelete": false } } } ### Get a customer's name, email, and default address Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query { customer(id: \\\"gid://shopify/Customer/544365967\\\") { email firstName lastName defaultAddress { address1 city province zip country } } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n email\n firstName\n lastName\n defaultAddress {\n address1\n city\n province\n zip\n country\n }\n }\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n email\n firstName\n lastName\n defaultAddress {\n address1\n city\n province\n zip\n country\n }\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n email\n firstName\n lastName\n defaultAddress {\n address1\n city\n province\n zip\n country\n }\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n email\n firstName\n lastName\n defaultAddress {\n address1\n city\n province\n zip\n country\n }\n }\n}" #### Graphql Input null #### Graphql Response { "data": { "customer": { "email": "bob@example.com", "firstName": "Bob", "lastName": "Bobsen", "defaultAddress": { "address1": "123 Amoebobacterieae St", "city": "Ottawa", "province": "Ontario", "zip": "K2P0V6", "country": "Canada" } } } } ### Get a metafield attached to a customer Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query CustomerMetafield($namespace: String!, $key: String!, $ownerId: ID!) { customer(id: $ownerId) { nickname: metafield(namespace: $namespace, key: $key) { value } } }\",\n \"variables\": {\n \"namespace\": \"my_fields\",\n \"key\": \"nickname\",\n \"ownerId\": \"gid://shopify/Customer/544365967\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `query CustomerMetafield($namespace: String!, $key: String!, $ownerId: ID!) {\n customer(id: $ownerId) {\n nickname: metafield(namespace: $namespace, key: $key) {\n value\n }\n }\n }`,\n \"variables\": {\n \"namespace\": \"my_fields\",\n \"key\": \"nickname\",\n \"ownerId\": \"gid://shopify/Customer/544365967\"\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query CustomerMetafield($namespace: String!, $key: String!, $ownerId: ID!) {\n customer(id: $ownerId) {\n nickname: metafield(namespace: $namespace, key: $key) {\n value\n }\n }\n }\nQUERY\n\nvariables = {\n \"namespace\": \"my_fields\",\n \"key\": \"nickname\",\n \"ownerId\": \"gid://shopify/Customer/544365967\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query CustomerMetafield($namespace: String!, $key: String!, $ownerId: ID!) {\n customer(id: $ownerId) {\n nickname: metafield(namespace: $namespace, key: $key) {\n value\n }\n }\n }`,\n {\n variables: {\n \"namespace\": \"my_fields\",\n \"key\": \"nickname\",\n \"ownerId\": \"gid://shopify/Customer/544365967\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "query CustomerMetafield($namespace: String!, $key: String!, $ownerId: ID!) {\n customer(id: $ownerId) {\n nickname: metafield(namespace: $namespace, key: $key) {\n value\n }\n }\n}" #### Graphql Input { "namespace": "my_fields", "key": "nickname", "ownerId": "gid://shopify/Customer/544365967" } #### Graphql Response { "data": { "customer": { "nickname": { "value": "rob" } } } } ### Get all a customer's fields and connections Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query { customer(id: \\\"gid://shopify/Customer/544365967\\\") { addresses(first: 5) { address1 } canDelete createdAt defaultAddress { address1 } displayName email events(first: 5) { edges { node { message } } } firstName id image { id } lastName legacyResourceId lifetimeDuration mergeable { isMergeable reason } metafield(key: \\\"app_key\\\", namespace: \\\"affiliates\\\") { description } metafields(first: 5) { edges { node { id } } } note orders(first: 5) { edges { node { id } } } numberOfOrders phone state tags taxExempt amountSpent { amount } updatedAt validEmailAddress verifiedEmail } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n addresses(first: 5) {\n address1\n }\n canDelete\n createdAt\n defaultAddress {\n address1\n }\n displayName\n email\n events(first: 5) {\n edges {\n node {\n message\n }\n }\n }\n firstName\n id\n image {\n id\n }\n lastName\n legacyResourceId\n lifetimeDuration\n mergeable {\n isMergeable\n reason\n }\n metafield(key: \"app_key\", namespace: \"affiliates\") {\n description\n }\n metafields(first: 5) {\n edges {\n node {\n id\n }\n }\n }\n note\n orders(first: 5) {\n edges {\n node {\n id\n }\n }\n }\n numberOfOrders\n phone\n state\n tags\n taxExempt\n amountSpent {\n amount\n }\n updatedAt\n validEmailAddress\n verifiedEmail\n }\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n addresses(first: 5) {\n address1\n }\n canDelete\n createdAt\n defaultAddress {\n address1\n }\n displayName\n email\n events(first: 5) {\n edges {\n node {\n message\n }\n }\n }\n firstName\n id\n image {\n id\n }\n lastName\n legacyResourceId\n lifetimeDuration\n mergeable {\n isMergeable\n reason\n }\n metafield(key: \"app_key\", namespace: \"affiliates\") {\n description\n }\n metafields(first: 5) {\n edges {\n node {\n id\n }\n }\n }\n note\n orders(first: 5) {\n edges {\n node {\n id\n }\n }\n }\n numberOfOrders\n phone\n state\n tags\n taxExempt\n amountSpent {\n amount\n }\n updatedAt\n validEmailAddress\n verifiedEmail\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n addresses(first: 5) {\n address1\n }\n canDelete\n createdAt\n defaultAddress {\n address1\n }\n displayName\n email\n events(first: 5) {\n edges {\n node {\n message\n }\n }\n }\n firstName\n id\n image {\n id\n }\n lastName\n legacyResourceId\n lifetimeDuration\n mergeable {\n isMergeable\n reason\n }\n metafield(key: \"app_key\", namespace: \"affiliates\") {\n description\n }\n metafields(first: 5) {\n edges {\n node {\n id\n }\n }\n }\n note\n orders(first: 5) {\n edges {\n node {\n id\n }\n }\n }\n numberOfOrders\n phone\n state\n tags\n taxExempt\n amountSpent {\n amount\n }\n updatedAt\n validEmailAddress\n verifiedEmail\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "query {\n customer(id: \"gid://shopify/Customer/544365967\") {\n addresses(first: 5) {\n address1\n }\n canDelete\n createdAt\n defaultAddress {\n address1\n }\n displayName\n email\n events(first: 5) {\n edges {\n node {\n message\n }\n }\n }\n firstName\n id\n image {\n id\n }\n lastName\n legacyResourceId\n lifetimeDuration\n mergeable {\n isMergeable\n reason\n }\n metafield(key: \"app_key\", namespace: \"affiliates\") {\n description\n }\n metafields(first: 5) {\n edges {\n node {\n id\n }\n }\n }\n note\n orders(first: 5) {\n edges {\n node {\n id\n }\n }\n }\n numberOfOrders\n phone\n state\n tags\n taxExempt\n amountSpent {\n amount\n }\n updatedAt\n validEmailAddress\n verifiedEmail\n }\n}" #### Graphql Input null #### Graphql Response { "data": { "customer": { "addresses": [ { "address1": "123 Amoebobacterieae St" } ], "canDelete": false, "createdAt": "2005-06-15T15:57:11Z", "defaultAddress": { "address1": "123 Amoebobacterieae St" }, "displayName": "Bob Bobsen", "email": "bob@example.com", "events": { "edges": [] }, "firstName": "Bob", "id": "gid://shopify/Customer/544365967", "image": { "id": null }, "lastName": "Bobsen", "legacyResourceId": "544365967", "lifetimeDuration": "over 19 years", "mergeable": { "isMergeable": false, "reason": "Bob Bobsen is scheduled for redaction or has been redacted and can’t be merged." }, "metafield": null, "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/749520593" } } ] }, "note": null, "orders": { "edges": [ { "node": { "id": "gid://shopify/Order/116757651" } }, { "node": { "id": "gid://shopify/Order/126216516" } }, { "node": { "id": "gid://shopify/Order/148977776" } }, { "node": { "id": "gid://shopify/Order/215577410" } }, { "node": { "id": "gid://shopify/Order/235240302" } } ] }, "numberOfOrders": "25", "phone": "+13125551212", "state": "ENABLED", "tags": [ "Bob", "Canadian", "Léon", "Noël" ], "taxExempt": false, "amountSpent": { "amount": "8305.6" }, "updatedAt": "2005-06-16T15:57:11Z", "validEmailAddress": true, "verifiedEmail": true } } } ### Get metafields attached to a customer Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query CustomerMetafields($ownerId: ID!) { customer(id: $ownerId) { metafields(first: 3) { edges { node { namespace key value } } } } }\",\n \"variables\": {\n \"ownerId\": \"gid://shopify/Customer/544365967\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `query CustomerMetafields($ownerId: ID!) {\n customer(id: $ownerId) {\n metafields(first: 3) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n }`,\n \"variables\": {\n \"ownerId\": \"gid://shopify/Customer/544365967\"\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query CustomerMetafields($ownerId: ID!) {\n customer(id: $ownerId) {\n metafields(first: 3) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"ownerId\": \"gid://shopify/Customer/544365967\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query CustomerMetafields($ownerId: ID!) {\n customer(id: $ownerId) {\n metafields(first: 3) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n }`,\n {\n variables: {\n \"ownerId\": \"gid://shopify/Customer/544365967\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "query CustomerMetafields($ownerId: ID!) {\n customer(id: $ownerId) {\n metafields(first: 3) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n}" #### Graphql Input { "ownerId": "gid://shopify/Customer/544365967" } #### Graphql Response { "data": { "customer": { "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "nickname", "value": "rob" } } ] } } } } ### Get pinned metafield definitions associated with a customer Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query CustomerMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) { customer(id: $ownerId) { metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) { edges { node { name namespace key type { name } } } } } }\",\n \"variables\": {\n \"pinnedStatus\": \"PINNED\",\n \"ownerId\": \"gid://shopify/Customer/544365967\",\n \"first\": 10,\n \"sortKey\": \"PINNED_POSITION\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `query CustomerMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) {\n customer(id: $ownerId) {\n metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) {\n edges {\n node {\n name\n namespace\n key\n type {\n name\n }\n }\n }\n }\n }\n }`,\n \"variables\": {\n \"pinnedStatus\": \"PINNED\",\n \"ownerId\": \"gid://shopify/Customer/544365967\",\n \"first\": 10,\n \"sortKey\": \"PINNED_POSITION\"\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query CustomerMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) {\n customer(id: $ownerId) {\n metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) {\n edges {\n node {\n name\n namespace\n key\n type {\n name\n }\n }\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"pinnedStatus\": \"PINNED\",\n \"ownerId\": \"gid://shopify/Customer/544365967\",\n \"first\": 10,\n \"sortKey\": \"PINNED_POSITION\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query CustomerMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) {\n customer(id: $ownerId) {\n metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) {\n edges {\n node {\n name\n namespace\n key\n type {\n name\n }\n }\n }\n }\n }\n }`,\n {\n variables: {\n \"pinnedStatus\": \"PINNED\",\n \"ownerId\": \"gid://shopify/Customer/544365967\",\n \"first\": 10,\n \"sortKey\": \"PINNED_POSITION\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "query CustomerMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) {\n customer(id: $ownerId) {\n metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) {\n edges {\n node {\n name\n namespace\n key\n type {\n name\n }\n }\n }\n }\n }\n}" #### Graphql Input { "pinnedStatus": "PINNED", "ownerId": "gid://shopify/Customer/544365967", "first": 10, "sortKey": "PINNED_POSITION" } #### Graphql Response { "data": { "customer": { "metafieldDefinitions": { "edges": [ { "node": { "name": "Pronouns", "namespace": "my_fields", "key": "pronouns", "type": { "name": "single_line_text_field" } } }, { "node": { "name": "Nickname", "namespace": "my_fields", "key": "nickname", "type": { "name": "single_line_text_field" } } } ] } } } } ### Get the email, name, and account creation date of three customers using a fragment Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query { Bob: customer(id: \\\"gid://shopify/Customer/544365967\\\") { ...customerProfile } Jane: customer(id: \\\"gid://shopify/Customer/567375318\\\") { ...customerProfile } Jenny: customer(id: \\\"gid://shopify/Customer/56501169\\\") { ...customerProfile } } fragment customerProfile on Customer { firstName lastName email createdAt }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `query {\n Bob: customer(id: \"gid://shopify/Customer/544365967\") {\n ...customerProfile\n }\n Jane: customer(id: \"gid://shopify/Customer/567375318\") {\n ...customerProfile\n }\n Jenny: customer(id: \"gid://shopify/Customer/56501169\") {\n ...customerProfile\n }\n }\n \n fragment customerProfile on Customer {\n firstName\n lastName\n email\n createdAt\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query {\n Bob: customer(id: \"gid://shopify/Customer/544365967\") {\n ...customerProfile\n }\n Jane: customer(id: \"gid://shopify/Customer/567375318\") {\n ...customerProfile\n }\n Jenny: customer(id: \"gid://shopify/Customer/56501169\") {\n ...customerProfile\n }\n }\n \n fragment customerProfile on Customer {\n firstName\n lastName\n email\n createdAt\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query {\n Bob: customer(id: \"gid://shopify/Customer/544365967\") {\n ...customerProfile\n }\n Jane: customer(id: \"gid://shopify/Customer/567375318\") {\n ...customerProfile\n }\n Jenny: customer(id: \"gid://shopify/Customer/56501169\") {\n ...customerProfile\n }\n }\n \n fragment customerProfile on Customer {\n firstName\n lastName\n email\n createdAt\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "query {\n Bob: customer(id: \"gid://shopify/Customer/544365967\") {\n ...customerProfile\n }\n Jane: customer(id: \"gid://shopify/Customer/567375318\") {\n ...customerProfile\n }\n Jenny: customer(id: \"gid://shopify/Customer/56501169\") {\n ...customerProfile\n }\n}\n\nfragment customerProfile on Customer {\n firstName\n lastName\n email\n createdAt\n}" #### Graphql Input null #### Graphql Response { "data": { "Bob": { "firstName": "Bob", "lastName": "Bobsen", "email": "bob@example.com", "createdAt": "2005-06-15T15:57:11Z" }, "Jane": { "firstName": "Jane", "lastName": "Smith", "email": "janesmith@b2b.example.com", "createdAt": "2024-11-04T18:56:43Z" }, "Jenny": { "firstName": "Jenny", "lastName": "Test", "email": "jennytest@b2b.example.com", "createdAt": "2024-11-04T18:56:43Z" } } } ### Get the first five line items of the customer's last order Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query { customer(id: \\\"gid://shopify/Customer/624407574\\\") { lastOrder { lineItems(first: 5) { edges { node { name quantity } } } } } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `query {\n customer(id: \"gid://shopify/Customer/624407574\") {\n lastOrder {\n lineItems(first: 5) {\n edges {\n node {\n name\n quantity\n }\n }\n }\n }\n }\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query {\n customer(id: \"gid://shopify/Customer/624407574\") {\n lastOrder {\n lineItems(first: 5) {\n edges {\n node {\n name\n quantity\n }\n }\n }\n }\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query {\n customer(id: \"gid://shopify/Customer/624407574\") {\n lastOrder {\n lineItems(first: 5) {\n edges {\n node {\n name\n quantity\n }\n }\n }\n }\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "query {\n customer(id: \"gid://shopify/Customer/624407574\") {\n lastOrder {\n lineItems(first: 5) {\n edges {\n node {\n name\n quantity\n }\n }\n }\n }\n }\n}" #### Graphql Input null #### Graphql Response { "data": { "customer": { "lastOrder": { "lineItems": { "edges": [ { "node": { "name": "Draft - 151cm", "quantity": 1 } } ] } } } } } ### Get the merge status of a customer Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query { customer(id: \\\"gid://shopify/Customer/105906728\\\") { mergeable { isMergeable reason errorFields mergeInProgress { jobId status resultingCustomerId customerMergeErrors { errorFields message } } } } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `query {\n customer(id: \"gid://shopify/Customer/105906728\") {\n mergeable {\n isMergeable\n reason\n errorFields\n mergeInProgress {\n jobId\n status\n resultingCustomerId\n customerMergeErrors {\n errorFields\n message\n }\n }\n }\n }\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query {\n customer(id: \"gid://shopify/Customer/105906728\") {\n mergeable {\n isMergeable\n reason\n errorFields\n mergeInProgress {\n jobId\n status\n resultingCustomerId\n customerMergeErrors {\n errorFields\n message\n }\n }\n }\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query {\n customer(id: \"gid://shopify/Customer/105906728\") {\n mergeable {\n isMergeable\n reason\n errorFields\n mergeInProgress {\n jobId\n status\n resultingCustomerId\n customerMergeErrors {\n errorFields\n message\n }\n }\n }\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "query {\n customer(id: \"gid://shopify/Customer/105906728\") {\n mergeable {\n isMergeable\n reason\n errorFields\n mergeInProgress {\n jobId\n status\n resultingCustomerId\n customerMergeErrors {\n errorFields\n message\n }\n }\n }\n }\n}" #### Graphql Input null #### Graphql Response { "data": { "customer": { "mergeable": { "isMergeable": false, "reason": "John Smith is scheduled for redaction or has been redacted and can’t be merged.", "errorFields": [ "REDACTED_AT" ], "mergeInProgress": null } } } } ### Get two specific customers by their ID using aliases Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query { bob: customer(id: \\\"gid://shopify/Customer/544365967\\\") { firstName lastName email } john: customer(id: \\\"gid://shopify/Customer/105906728\\\") { firstName lastName email } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `query {\n bob: customer(id: \"gid://shopify/Customer/544365967\") {\n firstName\n lastName\n email\n }\n john: customer(id: \"gid://shopify/Customer/105906728\") {\n firstName\n lastName\n email\n }\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query {\n bob: customer(id: \"gid://shopify/Customer/544365967\") {\n firstName\n lastName\n email\n }\n john: customer(id: \"gid://shopify/Customer/105906728\") {\n firstName\n lastName\n email\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query {\n bob: customer(id: \"gid://shopify/Customer/544365967\") {\n firstName\n lastName\n email\n }\n john: customer(id: \"gid://shopify/Customer/105906728\") {\n firstName\n lastName\n email\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "query {\n bob: customer(id: \"gid://shopify/Customer/544365967\") {\n firstName\n lastName\n email\n }\n john: customer(id: \"gid://shopify/Customer/105906728\") {\n firstName\n lastName\n email\n }\n}" #### Graphql Input null #### Graphql Response { "data": { "bob": { "firstName": "Bob", "lastName": "Bobsen", "email": "bob@example.com" }, "john": { "firstName": "John", "lastName": "Smith", "email": "johnsmith@example.com" } } }