--- title: customerSet - GraphQL Admin description: >- Creates or updates a customer in a single mutation. Use this mutation when syncing information from an external data source into Shopify. This mutation can be used to create a new customer, update an existing customer by id, or upsert a customer by a unique key (email or phone). To create a new customer omit the `identifier` argument. To update an existing customer, include the `identifier` with the id of the customer to update. To perform an 'upsert' by unique key (email or phone) use the `identifier` argument to upsert a customer by a unique key (email or phone). If a customer with the specified unique key exists, it will be updated. If not, a new customer will be created with that unique key. 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) Any list field (e.g. [addresses](https://shopify.dev/api/admin-graphql/unstable/input-objects/MailingAddressInput), will be updated so that all included entries are either created or updated, and all existing entries not included will be deleted. All other fields will be updated to the value passed. Omitted fields will not be updated. api_version: unstable api_name: admin source_url: html: 'https://shopify.dev/docs/api/admin-graphql/unstable/mutations/customerSet' md: 'https://shopify.dev/docs/api/admin-graphql/unstable/mutations/customerSet.md' --- # customer​Set mutation Requires `write_customers` access scope. Creates or updates a customer in a single mutation. Use this mutation when syncing information from an external data source into Shopify. This mutation can be used to create a new customer, update an existing customer by id, or upsert a customer by a unique key (email or phone). To create a new customer omit the `identifier` argument. To update an existing customer, include the `identifier` with the id of the customer to update. To perform an 'upsert' by unique key (email or phone) use the `identifier` argument to upsert a customer by a unique key (email or phone). If a customer with the specified unique key exists, it will be updated. If not, a new customer will be created with that unique key. 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) Any list field (e.g. [addresses](https://shopify.dev/api/admin-graphql/unstable/input-objects/MailingAddressInput), will be updated so that all included entries are either created or updated, and all existing entries not included will be deleted. All other fields will be updated to the value passed. Omitted fields will not be updated. ## Arguments * identifier [Customer​Set​Identifiers](https://shopify.dev/docs/api/admin-graphql/unstable/input-objects/CustomerSetIdentifiers) Specifies the identifier that will be used to lookup the resource. * input [Customer​Set​Input!](https://shopify.dev/docs/api/admin-graphql/unstable/input-objects/CustomerSetInput) required The properties of the customer. *** ## Customer​Set​Payload returns * customer [Customer](https://shopify.dev/docs/api/admin-graphql/unstable/objects/Customer) The created or updated customer. * user​Errors [\[Customer​Set​User​Error!\]!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/CustomerSetUserError) non-null The list of errors that occurred from executing the mutation. *** ## Examples * ### Create a customer #### Query ```graphql mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } } ``` #### Variables ```json { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } }", "variables": { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } }`, { variables: { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby 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 mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } } QUERY variables = { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } }`, "variables": { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } }, }, }); ``` #### Response ```json { "customerSet": { "customer": { "id": "gid://shopify/Customer/1073339466" }, "userErrors": [] } } ``` * ### Update a customer's first and last name #### Description Update a customer's first and last name #### Query ```graphql mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } } ``` #### Variables ```json { "input": { "firstName": "Steve", "lastName": "Lastname" }, "identifier": { "id": "gid://shopify/Customer/1018520244" } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } }", "variables": { "input": { "firstName": "Steve", "lastName": "Lastname" }, "identifier": { "id": "gid://shopify/Customer/1018520244" } } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } }`, { variables: { "input": { "firstName": "Steve", "lastName": "Lastname" }, "identifier": { "id": "gid://shopify/Customer/1018520244" } }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby 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 mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } } QUERY variables = { "input": { "firstName": "Steve", "lastName": "Lastname" }, "identifier": { "id": "gid://shopify/Customer/1018520244" } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } }`, "variables": { "input": { "firstName": "Steve", "lastName": "Lastname" }, "identifier": { "id": "gid://shopify/Customer/1018520244" } }, }, }); ``` #### Response ```json { "customerSet": { "userErrors": [], "customer": { "id": "gid://shopify/Customer/1018520244", "firstName": "Steve", "lastName": "Lastname" } } } ``` * ### Upsert a customer by email address #### Description Upsert a customer by email address #### Query ```graphql mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } } ``` #### Variables ```json { "identifier": { "email": "bob@example.org" }, "input": { "email": "bob@example.org", "firstName": "Steve", "lastName": "Lastname" } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } }", "variables": { "identifier": { "email": "bob@example.org" }, "input": { "email": "bob@example.org", "firstName": "Steve", "lastName": "Lastname" } } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } }`, { variables: { "identifier": { "email": "bob@example.org" }, "input": { "email": "bob@example.org", "firstName": "Steve", "lastName": "Lastname" } }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby 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 mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } } QUERY variables = { "identifier": { "email": "bob@example.org" }, "input": { "email": "bob@example.org", "firstName": "Steve", "lastName": "Lastname" } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } }`, "variables": { "identifier": { "email": "bob@example.org" }, "input": { "email": "bob@example.org", "firstName": "Steve", "lastName": "Lastname" } }, }, }); ``` #### Response ```json { "customerSet": { "userErrors": [], "customer": { "id": "gid://shopify/Customer/1018520244", "firstName": "Steve", "lastName": "Lastname" } } } ``` * ### customerSet reference [Open in GraphiQL](http://localhost:3457/graphiql?query=mutation%20createCustomer\(%24input%3A%20CustomerSetInput!\)%20%7B%0A%20%20customerSet\(input%3A%20%24input\)%20%7B%0A%20%20%20%20customer%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%7D%0A%20%20%20%20userErrors%20%7B%0A%20%20%20%20%20%20code%0A%20%20%20%20%20%20field%0A%20%20%20%20%20%20message%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D\&variables=%7B%0A%20%20%22input%22%3A%20%7B%0A%20%20%20%20%22email%22%3A%20%22steve.lastnameson%40example.com%22%2C%0A%20%20%20%20%22phone%22%3A%20%22%2B16465555555%22%2C%0A%20%20%20%20%22firstName%22%3A%20%22Steve%22%2C%0A%20%20%20%20%22lastName%22%3A%20%22Lastname%22%0A%20%20%7D%0A%7D) ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } }`, { variables: { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } }, }, ); const json = await response.json(); return json.data; } ``` ##### GQL ``` mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } } ``` ##### cURL ``` curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } }", "variables": { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } } }' ``` ##### React Router ``` import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } }`, { variables: { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } }, }, ); const json = await response.json(); return json.data; } ``` ##### Node.js ``` const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } }`, "variables": { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } }, }, }); ``` ##### Ruby ``` 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 mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } } QUERY variables = { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } } response = client.query(query: query, variables: variables) ``` ## Input variables JSON ```json { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } } ``` ## Response JSON ```json { "customerSet": { "customer": { "id": "gid://shopify/Customer/1073339466" }, "userErrors": [] } } ```