# customerUpdate - admin-graphql - MUTATION Version: 2024-07 ## Description 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). ### Access Scopes `write_customers` access scope. ## Arguments * [input](/docs/api/admin-graphql/2024-07/input-objects/CustomerInput): CustomerInput! - Provides updated fields for the customer. To set marketing consent, use the `customerEmailMarketingConsentUpdate` or `customerSmsMarketingConsentUpdate` mutations instead. ## Returns * [customer](/docs/api/admin-graphql/2024-07/objects/Customer): Customer The updated customer. * [userErrors](/docs/api/admin-graphql/2024-07/objects/UserError): UserError! The list of errors that occurred from executing the mutation. ## Examples ### Create a new metafield and update another on an existing customer Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/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/1069230189\",\n \"value\": \"they/them\"\n }\n ],\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 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/1069230189\",\n \"value\": \"they/them\"\n }\n ],\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 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/1069230189\", \"value\"=>\"they/them\"}],\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 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/1069230189\",\n \"value\": \"they/them\"\n }\n ],\n \"id\": \"gid://shopify/Customer/1018520244\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql 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}" #### Graphql Input { "input": { "metafields": [ { "namespace": "my_field", "key": "nickname", "type": "single_line_text_field", "value": "rob" }, { "id": "gid://shopify/Metafield/1069230189", "value": "they/them" } ], "id": "gid://shopify/Customer/1018520244" } } #### Graphql Response { "data": { "customerUpdate": { "customer": { "id": "gid://shopify/Customer/1018520244", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069230189", "namespace": "my_field", "key": "pronouns", "value": "they/them" } }, { "node": { "id": "gid://shopify/Metafield/1069230190", "namespace": "my_field", "key": "nickname", "value": "rob" } } ] } }, "userErrors": [] } } } ### Update a customer with an ID that doesn't exist Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/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" 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" 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" 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" Graphql 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}" #### Graphql Input { "input": { "id": "gid://shopify/Customer/1", "firstName": "Tobi" } } #### Graphql Response { "data": { "customerUpdate": { "userErrors": [ { "field": [ "id" ], "message": "Customer does not exist" } ], "customer": null } } } ### Updates a customer's first and last name Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/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" 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" 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" 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" Graphql 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}" #### Graphql Input { "input": { "id": "gid://shopify/Customer/1018520244", "firstName": "Tobi", "lastName": "Lutke" } } #### Graphql Response { "data": { "customerUpdate": { "userErrors": [], "customer": { "id": "gid://shopify/Customer/1018520244", "firstName": "Tobi", "lastName": "Lutke" } } } }