customer Updatemutation
mutation
2024-10latest
Requires write
access scope. Also: User needs customers permission.
Update a customer's attributes. As of API version 2022-10, apps using protected customer data must meet the protected customer data requirements.
Arguments
Provides updated fields for the customer. To set marketing consent, use the
customer
orEmail Marketing Consent Update customer
mutations instead.Sms Marketing Consent Update
Was this section helpful?
CustomerUpdatePayload returns
The updated customer.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: customerUpdate
Query Reference for MUTATION: customerUpdate
"mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n customer {\n # Customer fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: customerUpdate
"{\n \"input\": {\n \"addresses\": [\n {\n \"address1\": \"<your-address1>\",\n \"address2\": \"<your-address2>\",\n \"city\": \"<your-city>\",\n \"company\": \"<your-company>\",\n \"country\": \"<your-country>\",\n \"countryCode\": \"AC\",\n \"firstName\": \"<your-firstName>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"lastName\": \"<your-lastName>\",\n \"phone\": \"<your-phone>\",\n \"province\": \"<your-province>\",\n \"provinceCode\": \"<your-provinceCode>\",\n \"zip\": \"<your-zip>\"\n }\n ],\n \"email\": \"<your-email>\",\n \"emailMarketingConsent\": {\n \"consentUpdatedAt\": \"2019-09-07T15:50:00Z\",\n \"marketingOptInLevel\": \"CONFIRMED_OPT_IN\",\n \"marketingState\": \"INVALID\"\n },\n \"firstName\": \"<your-firstName>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"lastName\": \"<your-lastName>\",\n \"locale\": \"<your-locale>\",\n \"metafields\": [\n {\n \"description\": \"<your-description>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"key\": \"<your-key>\",\n \"namespace\": \"<your-namespace>\",\n \"type\": \"<your-type>\",\n \"value\": \"<your-value>\"\n }\n ],\n \"note\": \"<your-note>\",\n \"phone\": \"<your-phone>\",\n \"smsMarketingConsent\": {\n \"consentUpdatedAt\": \"2019-09-07T15:50:00Z\",\n \"marketingOptInLevel\": \"CONFIRMED_OPT_IN\",\n \"marketingState\": \"NOT_SUBSCRIBED\"\n },\n \"tags\": [\n \"<your-tags>\"\n ],\n \"taxExempt\": true,\n \"taxExemptions\": [\n \"CA_BC_COMMERCIAL_FISHERY_EXEMPTION\"\n ]\n }\n}"
Schema Reference for MUTATION: customerUpdate
"input CustomerInput {\n addresses: [MailingAddressInput!]\n email: String\n emailMarketingConsent: CustomerEmailMarketingConsentInput\n firstName: String\n id: ID\n lastName: String\n locale: String\n metafields: [MetafieldInput!]\n note: String\n phone: String\n privateMetafields: [PrivateMetafieldInput!]\n smsMarketingConsent: CustomerSmsMarketingConsentInput\n tags: [String!]\n taxExempt: Boolean\n taxExemptions: [TaxExemption!]\n}\n\ninput MailingAddressInput {\n address1: String\n address2: String\n city: String\n company: String\n country: String\n countryCode: CountryCode\n firstName: String\n id: ID\n lastName: String\n phone: String\n province: String\n provinceCode: String\n zip: String\n}\n\ninput CustomerEmailMarketingConsentInput {\n consentUpdatedAt: DateTime\n marketingOptInLevel: CustomerMarketingOptInLevel\n marketingState: CustomerEmailMarketingState!\n}\n\ninput MetafieldInput {\n description: String\n id: ID\n key: String\n namespace: String\n type: String\n value: String\n}\n\ninput PrivateMetafieldInput {\n key: String!\n namespace: String!\n owner: ID\n valueInput: PrivateMetafieldValueInput!\n}\n\ninput CustomerSmsMarketingConsentInput {\n consentUpdatedAt: DateTime\n marketingOptInLevel: CustomerMarketingOptInLevel\n marketingState: CustomerSmsMarketingState!\n}\n"
Display Examples for MUTATION: customerUpdate
[ { "example": { "type_name": "customerupdate", "title": "Create a new metafield and update another on an existing customer", "description": "Create a new metafield `my_field.nickname` and update an\nexisting metafield `my_field.pronouns` on a specific\ncustomer.\n\n\nAlternatively, refer to the\n[metafieldsSet](https://shopify.dev/api/admin-graphql/latest/mutations/metafieldsset) mutation\nto create and/or update metafields on customer resources.\n", "query_string": "mutation updateCustomerMetafields($input: CustomerInput!) {\n customerUpdate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n}", "variables": { "input": { "metafields": [ { "namespace": "my_field", "key": "nickname", "type": "single_line_text_field", "value": "rob" }, { "id": "gid://shopify/Metafield/1069229111", "value": "they/them" } ], "id": "gid://shopify/Customer/1018520244" } }, "response": { "data": { "customerUpdate": { "customer": { "id": "gid://shopify/Customer/1018520244", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069229111", "namespace": "my_field", "key": "pronouns", "value": "they/them" } }, { "node": { "id": "gid://shopify/Metafield/1069229112", "namespace": "my_field", "key": "nickname", "value": "rob" } } ] } }, "userErrors": [] } } }, "api_name": "admin", "location": "/components/customers/test/unit/graph_api/admin/mutations/customer_update_test.rb", "minimum_api_version": null, "maximum_api_version": null, "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation updateCustomerMetafields($input: CustomerInput!) { customerUpdate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }\",\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"nickname\",\n \"type\": \"single_line_text_field\",\n \"value\": \"rob\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069229111\",\n \"value\": \"they/them\"\n }\n ],\n \"id\": \"gid://shopify/Customer/1018520244\"\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation updateCustomerMetafields($input: CustomerInput!) {\n customerUpdate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"nickname\",\n \"type\": \"single_line_text_field\",\n \"value\": \"rob\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069229111\",\n \"value\": \"they/them\"\n }\n ],\n \"id\": \"gid://shopify/Customer/1018520244\"\n }\n },\n },\n);\n\nconst data = await response.json();\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 updateCustomerMetafields($input: CustomerInput!) {\n customerUpdate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"metafields\": [{\"namespace\"=>\"my_field\", \"key\"=>\"nickname\", \"type\"=>\"single_line_text_field\", \"value\"=>\"rob\"}, {\"id\"=>\"gid://shopify/Metafield/1069229111\", \"value\"=>\"they/them\"}],\n \"id\": \"gid://shopify/Customer/1018520244\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation updateCustomerMetafields($input: CustomerInput!) {\n customerUpdate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"nickname\",\n \"type\": \"single_line_text_field\",\n \"value\": \"rob\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069229111\",\n \"value\": \"they/them\"\n }\n ],\n \"id\": \"gid://shopify/Customer/1018520244\"\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation updateCustomerMetafields($input: CustomerInput!) {\n customerUpdate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"metafields\" => [{\"namespace\"=>\"my_field\", \"key\"=>\"nickname\", \"type\"=>\"single_line_text_field\", \"value\"=>\"rob\"}, {\"id\"=>\"gid://shopify/Metafield/1069229111\", \"value\"=>\"they/them\"}],\n \"id\" => \"gid://shopify/Customer/1018520244\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "Provides updated fields for the customer. To set marketing consent, use the `customerEmailMarketingConsentUpdate` or `customerSmsMarketingConsentUpdate` mutations instead.", "type": { "kind": "INPUT_OBJECT", "name": "CustomerInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "CustomerInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"metafields\":[{\"namespace\":\"my_field\",\"key\":\"nickname\",\"type\":\"single_line_text_field\",\"value\":\"rob\"},{\"id\":\"gid://shopify/Metafield/1069229111\",\"value\":\"they/them\"}],\"id\":\"gid://shopify/Customer/1018520244\"}", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "customerupdate", "title": "Update a customer with an ID that doesn't exist", "description": "Trying to update a customer that doesn't exist will return an error", "query_string": "mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n }\n }\n}", "variables": { "input": { "id": "gid://shopify/Customer/1", "firstName": "Tobi" } }, "response": { "data": { "customerUpdate": { "userErrors": [ { "field": [ "id" ], "message": "Customer does not exist" } ], "customer": null } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/customers/test/unit/graph_api/admin/mutations/customer_update_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation customerUpdate($input: CustomerInput!) { customerUpdate(input: $input) { userErrors { field message } customer { id firstName } } }\",\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/Customer/1\",\n \"firstName\": \"Tobi\"\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"id\": \"gid://shopify/Customer/1\",\n \"firstName\": \"Tobi\"\n }\n },\n },\n);\n\nconst data = await response.json();\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 customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"id\": \"gid://shopify/Customer/1\",\n \"firstName\": \"Tobi\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/Customer/1\",\n \"firstName\": \"Tobi\"\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"id\" => \"gid://shopify/Customer/1\",\n \"firstName\" => \"Tobi\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "Provides updated fields for the customer. To set marketing consent, use the `customerEmailMarketingConsentUpdate` or `customerSmsMarketingConsentUpdate` mutations instead.", "type": { "kind": "INPUT_OBJECT", "name": "CustomerInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "CustomerInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"id\":\"gid://shopify/Customer/1\",\"firstName\":\"Tobi\"}", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "customerupdate", "title": "Updates a customer's first and last name", "description": "Update a customer's first and last name", "query_string": "mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n}", "variables": { "input": { "id": "gid://shopify/Customer/1018520244", "firstName": "Tobi", "lastName": "Lutke" } }, "response": { "data": { "customerUpdate": { "userErrors": [], "customer": { "id": "gid://shopify/Customer/1018520244", "firstName": "Tobi", "lastName": "Lutke" } } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/customers/test/unit/graph_api/admin/mutations/customer_update_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation customerUpdate($input: CustomerInput!) { customerUpdate(input: $input) { userErrors { field message } customer { id firstName lastName } } }\",\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/Customer/1018520244\",\n \"firstName\": \"Tobi\",\n \"lastName\": \"Lutke\"\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"id\": \"gid://shopify/Customer/1018520244\",\n \"firstName\": \"Tobi\",\n \"lastName\": \"Lutke\"\n }\n },\n },\n);\n\nconst data = await response.json();\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 customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"id\": \"gid://shopify/Customer/1018520244\",\n \"firstName\": \"Tobi\",\n \"lastName\": \"Lutke\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/Customer/1018520244\",\n \"firstName\": \"Tobi\",\n \"lastName\": \"Lutke\"\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation customerUpdate($input: CustomerInput!) {\n customerUpdate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n firstName\n lastName\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"id\" => \"gid://shopify/Customer/1018520244\",\n \"firstName\" => \"Tobi\",\n \"lastName\" => \"Lutke\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "Provides updated fields for the customer. To set marketing consent, use the `customerEmailMarketingConsentUpdate` or `customerSmsMarketingConsentUpdate` mutations instead.", "type": { "kind": "INPUT_OBJECT", "name": "CustomerInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "CustomerInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"id\":\"gid://shopify/Customer/1018520244\",\"firstName\":\"Tobi\",\"lastName\":\"Lutke\"}", "typeKind": "MUTATION" } ] } ]