Anchor to customerUpdatecustomer
customerUpdate
mutation
Requires access scope.
Update a customer's attributes. As of API version 2022-10, apps using protected customer data must meet the protected customer data requirements.
Anchor to Arguments
Arguments
- Anchor to inputinput•Customer
Input! required Provides updated fields for the customer. To set marketing consent, use the
or
mutations instead.
Was this section helpful?
Anchor to CustomerUpdatePayload returnsCustomerUpdatePayload returns
- Anchor to customercustomer•
The updated customer.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a new metafield and update another on an existing customer
- Creates a new address for a customer
- Performs bulk operations for multiple customer addresses
- Update a customer with an ID that doesn't exist
- Updates a customer's first and last name
- Updates an existing customer address
- customerUpdate reference
Examples
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",
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/1069230189",
"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/1069230189",
"value": "they/them"
}
],
"id": "gid://shopify/Customer/1018520244"
}
},
},
);
const data = await response.json();
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/1069230189",
"value": "they/them"
}
],
"id": "gid://shopify/Customer/1018520244"
}
},
},
});
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/1069230189", "value"=>"they/them"}],
"id": "gid://shopify/Customer/1018520244"
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"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"
}
}
Response
JSON{
"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": []
}
}