customer Updatemutation
mutation
2025-01release candidate
Requires
write_customers
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?
Examples
Hide code
DescriptionCopy
mutation updateCustomerMetafields($input: CustomerInput!) { customerUpdate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }
curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation updateCustomerMetafields($input: CustomerInput!) { customerUpdate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }", "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" } } }'
const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation updateCustomerMetafields($input: CustomerInput!) { customerUpdate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }`, { 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" } }, }, ); const data = await response.json();
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 updateCustomerMetafields($input: CustomerInput!) { customerUpdate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } } QUERY 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 = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation updateCustomerMetafields($input: CustomerInput!) { customerUpdate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }`, "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" } }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $query = <<<QUERY mutation updateCustomerMetafields($input: CustomerInput!) { customerUpdate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } } QUERY; $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 = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{ "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" } }
Hide code
Response
JSON
{ "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": [] } }