--- title: customer - Storefront API description: > The customer associated with the given access token. Tokens are obtained by using the [`customerAccessTokenCreate` mutation](https://shopify.dev/docs/api/storefront/latest/mutations/customerAccessTokenCreate). api_version: unstable api_name: storefront source_url: html: 'https://shopify.dev/docs/api/storefront/unstable/queries/customer' md: 'https://shopify.dev/docs/api/storefront/unstable/queries/customer.md' --- # customer query The customer associated with the given access token. Tokens are obtained by using the [`customerAccessTokenCreate` mutation](https://shopify.dev/docs/api/storefront/latest/mutations/customerAccessTokenCreate). ## Arguments * customer​Access​Token [String!](https://shopify.dev/docs/api/storefront/unstable/scalars/String) required The customer access token. *** ## Possible returns * Customer [Customer](https://shopify.dev/docs/api/storefront/unstable/objects/Customer) A customer represents a customer account with the shop. Customer accounts store contact information for the customer, saving logged-in customers the trouble of having to provide it at every checkout. * accepts​Marketing [Boolean!](https://shopify.dev/docs/api/storefront/unstable/scalars/Boolean) non-null Token access required Indicates whether the customer has consented to be sent marketing material via email. * addresses [Mailing​Address​Connection!](https://shopify.dev/docs/api/storefront/unstable/connections/MailingAddressConnection) non-null Token access required A list of addresses for the customer. * first [Int](https://shopify.dev/docs/api/storefront/unstable/scalars/Int) ### Arguments Returns up to the first `n` elements from the list. * after [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Returns the elements that come after the specified cursor. * last [Int](https://shopify.dev/docs/api/storefront/unstable/scalars/Int) Returns up to the last `n` elements from the list. * before [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Returns the elements that come before the specified cursor. * reverse [Boolean](https://shopify.dev/docs/api/storefront/unstable/scalars/Boolean) Default:false Reverse the order of the underlying list. *** * avatar​Url [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Token access required The URL of the customer's avatar image. * created​At [Date​Time!](https://shopify.dev/docs/api/storefront/unstable/scalars/DateTime) non-null Token access required The date and time when the customer was created. * default​Address [Mailing​Address](https://shopify.dev/docs/api/storefront/unstable/objects/MailingAddress) Token access required The customer’s default address. * display​Name [String!](https://shopify.dev/docs/api/storefront/unstable/scalars/String) non-null Token access required The customer’s name, email or phone number. * email [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Token access required The customer’s email address. * first​Name [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Token access required The customer’s first name. * id [ID!](https://shopify.dev/docs/api/storefront/unstable/scalars/ID) non-null Token access required A unique ID for the customer. * last​Name [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Token access required The customer’s last name. * metafield [Metafield](https://shopify.dev/docs/api/storefront/unstable/objects/Metafield) Token access required 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. * namespace [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) ### Arguments The container the metafield belongs to. If omitted, the app-reserved namespace will be used. * key [String!](https://shopify.dev/docs/api/storefront/unstable/scalars/String) required The identifier for the metafield. *** * metafields [\[Metafield\]!](https://shopify.dev/docs/api/storefront/unstable/objects/Metafield) non-null Token access required A list of [custom fields](https://shopify.dev/docs/apps/build/custom-data) that a merchant associates with a Shopify resource. * identifiers [\[Has​Metafields​Identifier!\]!](https://shopify.dev/docs/api/storefront/unstable/input-objects/HasMetafieldsIdentifier) required ### Arguments The list of metafields to retrieve by namespace and key. The input must not contain more than `250` values. *** * number​Of​Orders [Unsigned​Int64!](https://shopify.dev/docs/api/storefront/unstable/scalars/UnsignedInt64) non-null Token access required The number of orders that the customer has made at the store in their lifetime. * orders [Order​Connection!](https://shopify.dev/docs/api/storefront/unstable/connections/OrderConnection) non-null Token access required The orders associated with the customer. * first [Int](https://shopify.dev/docs/api/storefront/unstable/scalars/Int) ### Arguments Returns up to the first `n` elements from the list. * after [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Returns the elements that come after the specified cursor. * last [Int](https://shopify.dev/docs/api/storefront/unstable/scalars/Int) Returns up to the last `n` elements from the list. * before [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Returns the elements that come before the specified cursor. * reverse [Boolean](https://shopify.dev/docs/api/storefront/unstable/scalars/Boolean) Default:false Reverse the order of the underlying list. * sort​Key [Order​Sort​Keys](https://shopify.dev/docs/api/storefront/unstable/enums/OrderSortKeys) Default:ID Sort the underlying list by the given key. * query [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Apply one or multiple filters to the query. Refer to the detailed [search syntax](https://shopify.dev/api/usage/search-syntax) for more information about using filters. * processed\_at *** * phone [String](https://shopify.dev/docs/api/storefront/unstable/scalars/String) Token access required The customer’s phone number. * tags [\[String!\]!](https://shopify.dev/docs/api/storefront/unstable/scalars/String) non-null Token access required A comma separated list of tags that have been added to the customer. Additional access scope required: unauthenticated\_read\_customer\_tags. * updated​At [Date​Time!](https://shopify.dev/docs/api/storefront/unstable/scalars/DateTime) non-null Token access required The date and time when the customer information was updated. *** ## Examples * ### Get a customer by access token #### Description The following query retrieves the customer with the associated access token. It returns the customer fields specified in the query. #### Query ```graphql query { customer(customerAccessToken: "bobs_token") { id firstName lastName acceptsMarketing email phone } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Storefront-Access-Token: {storefront_access_token}' \ -d '{ "query": "query { customer(customerAccessToken: \"bobs_token\") { id firstName lastName acceptsMarketing email phone } }" }' ``` #### React Router ```javascript import { unauthenticated } from "../shopify.server"; export const loader = async () => { const { storefront } = await unauthenticated.storefront( 'your-development-store.myshopify.com' ); const response = await storefront.graphql( `#graphql query { customer(customerAccessToken: "bobs_token") { id firstName lastName acceptsMarketing email phone } }`, ); const json = await response.json(); return json.data; } ``` #### Node.js ```javascript const client = new shopify.clients.Storefront({ domain: 'your-development-store.myshopify.com', storefrontAccessToken, }); const data = await client.query({ data: `query { customer(customerAccessToken: "bobs_token") { id firstName lastName acceptsMarketing email phone } }`, }); ``` #### Response ```json { "customer": { "id": "gid://shopify/Customer/410535040", "firstName": "John", "lastName": "Smith", "acceptsMarketing": false, "email": "johnsmith@example.com", "phone": "+16134504533" } } ``` ## Get a customer by access token [Open in GraphiQL](http://localhost:3457/graphiql?query=query%20%7B%0A%20%20customer\(customerAccessToken%3A%20%22bobs_token%22\)%20%7B%0A%20%20%20%20id%0A%20%20%20%20firstName%0A%20%20%20%20lastName%0A%20%20%20%20acceptsMarketing%0A%20%20%20%20email%0A%20%20%20%20phone%0A%20%20%7D%0A%7D) ##### GQL ```graphql query { customer(customerAccessToken: "bobs_token") { id firstName lastName acceptsMarketing email phone } } ``` ##### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Storefront-Access-Token: {storefront_access_token}' \ -d '{ "query": "query { customer(customerAccessToken: \"bobs_token\") { id firstName lastName acceptsMarketing email phone } }" }' ``` ##### React Router ```javascript import { unauthenticated } from "../shopify.server"; export const loader = async () => { const { storefront } = await unauthenticated.storefront( 'your-development-store.myshopify.com' ); const response = await storefront.graphql( `#graphql query { customer(customerAccessToken: "bobs_token") { id firstName lastName acceptsMarketing email phone } }`, ); const json = await response.json(); return json.data; } ``` ##### Node.js ```javascript const client = new shopify.clients.Storefront({ domain: 'your-development-store.myshopify.com', storefrontAccessToken, }); const data = await client.query({ data: `query { customer(customerAccessToken: "bobs_token") { id firstName lastName acceptsMarketing email phone } }`, }); ``` ## Response JSON ```json { "customer": { "id": "gid://shopify/Customer/410535040", "firstName": "John", "lastName": "Smith", "acceptsMarketing": false, "email": "johnsmith@example.com", "phone": "+16134504533" } } ```