# customerSet - admin - MUTATION Version: unstable ## 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. ### Access Scopes `write_customers` access scope. ## Arguments * [identifier](/docs/api/admin/unstable/input-objects/CustomerSetIdentifiers): CustomerSetIdentifiers - Specifies the identifier that will be used to lookup the resource. * [input](/docs/api/admin/unstable/input-objects/CustomerSetInput): CustomerSetInput! - The properties of the customer. ## Returns * [customer](/docs/api/admin/unstable/objects/Customer): Customer The created or updated customer. * [userErrors](/docs/api/admin/unstable/objects/CustomerSetUserError): CustomerSetUserError! The list of errors that occurred from executing the mutation. ## Examples ### Create a customer Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/unstable/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation createCustomer($input: CustomerSetInput!) { customerSet(input: $input) { customer { id } userErrors { code field message } } }\",\n \"variables\": {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation createCustomer($input: CustomerSetInput!) {\n customerSet(input: $input) {\n customer {\n id\n }\n userErrors {\n code\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\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 mutation createCustomer($input: CustomerSetInput!) {\n customerSet(input: $input) {\n customer {\n id\n }\n userErrors {\n code\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n }\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 mutation createCustomer($input: CustomerSetInput!) {\n customerSet(input: $input) {\n customer {\n id\n }\n userErrors {\n code\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation createCustomer($input: CustomerSetInput!) {\n customerSet(input: $input) {\n customer {\n id\n }\n userErrors {\n code\n field\n message\n }\n }\n}" #### Graphql Input { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "lastName": "Lastname" } } #### Graphql Response { "data": { "customerSet": { "customer": { "id": "gid://shopify/Customer/1073339466" }, "userErrors": [] } } } ### Update a customer's first and last name Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/unstable/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } }\",\n \"variables\": {\n \"input\": {\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n },\n \"identifier\": {\n \"id\": \"gid://shopify/Customer/1018520244\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) {\n customerSet(input: $input, identifier: $identifier) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n },\n \"identifier\": {\n \"id\": \"gid://shopify/Customer/1018520244\"\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 mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) {\n customerSet(input: $input, identifier: $identifier) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n },\n \"identifier\": {\n \"id\": \"gid://shopify/Customer/1018520244\"\n }\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 mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) {\n customerSet(input: $input, identifier: $identifier) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n },\n \"identifier\": {\n \"id\": \"gid://shopify/Customer/1018520244\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) {\n customerSet(input: $input, identifier: $identifier) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n}" #### Graphql Input { "input": { "firstName": "Steve", "lastName": "Lastname" }, "identifier": { "id": "gid://shopify/Customer/1018520244" } } #### Graphql Response { "data": { "customerSet": { "userErrors": [], "customer": { "id": "gid://shopify/Customer/1018520244", "firstName": "Steve", "lastName": "Lastname" } } } } ### Upsert a customer by email address Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/unstable/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) { customerSet(input: $input, identifier: $identifier) { userErrors { field message } customer { id firstName lastName } } }\",\n \"variables\": {\n \"identifier\": {\n \"email\": \"bob@example.org\"\n },\n \"input\": {\n \"email\": \"bob@example.org\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) {\n customerSet(input: $input, identifier: $identifier) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }`,\n \"variables\": {\n \"identifier\": {\n \"email\": \"bob@example.org\"\n },\n \"input\": {\n \"email\": \"bob@example.org\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\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 mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) {\n customerSet(input: $input, identifier: $identifier) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }\nQUERY\n\nvariables = {\n \"identifier\": {\n \"email\": \"bob@example.org\"\n },\n \"input\": {\n \"email\": \"bob@example.org\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n }\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 mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) {\n customerSet(input: $input, identifier: $identifier) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }`,\n {\n variables: {\n \"identifier\": {\n \"email\": \"bob@example.org\"\n },\n \"input\": {\n \"email\": \"bob@example.org\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation customerSet($input: CustomerSetInput!, $identifier: CustomerSetIdentifiers) {\n customerSet(input: $input, identifier: $identifier) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n}" #### Graphql Input { "identifier": { "email": "bob@example.org" }, "input": { "email": "bob@example.org", "firstName": "Steve", "lastName": "Lastname" } } #### Graphql Response { "data": { "customerSet": { "userErrors": [], "customer": { "id": "gid://shopify/Customer/1018520244", "firstName": "Steve", "lastName": "Lastname" } } } }