Anchor to customerUpdateDefaultAddresscustomer
customerUpdateDefaultAddress
mutation
Requires access scope.
Updates a customer's default address.
Anchor to Arguments
Arguments
- Anchor to addressIdaddress•
Id ID!required The ID of the customer's new default address.
- Anchor to customerIdcustomer•
Id ID!required The ID of the customer whose default address is being updated.
Was this section helpful?
Anchor to CustomerUpdateDefaultAddressPayload returnsCustomerUpdateDefaultAddressPayload returns
- Anchor to customercustomer•
The customer whose address was updated.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Sets the default address for a customer
- Updates an existing customer address
- customerUpdateDefaultAddress reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CustomerAddressDefault($addressId: ID!, $customerId: ID!) {
customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
customer {
id
defaultAddress {
id
address1
city
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"customerId": "gid://shopify/Customer/624407574",
"addressId": "gid://shopify/MailingAddress/624407574?model_name=CustomerAddress"
},
},
);
mutation CustomerAddressDefault($addressId: ID!, $customerId: ID!) {
customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
customer {
id
defaultAddress {
id
address1
city
}
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CustomerAddressDefault($addressId: ID!, $customerId: ID!) { customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) { customer { id defaultAddress { id address1 city } } userErrors { field message } } }",
"variables": {
"customerId": "gid://shopify/Customer/624407574",
"addressId": "gid://shopify/MailingAddress/624407574?model_name=CustomerAddress"
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CustomerAddressDefault($addressId: ID!, $customerId: ID!) {
customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
customer {
id
defaultAddress {
id
address1
city
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"customerId": "gid://shopify/Customer/624407574",
"addressId": "gid://shopify/MailingAddress/624407574?model_name=CustomerAddress"
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CustomerAddressDefault($addressId: ID!, $customerId: ID!) {
customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
customer {
id
defaultAddress {
id
address1
city
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"customerId": "gid://shopify/Customer/624407574",
"addressId": "gid://shopify/MailingAddress/624407574?model_name=CustomerAddress"
},
},
});
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 CustomerAddressDefault($addressId: ID!, $customerId: ID!) {
customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
customer {
id
defaultAddress {
id
address1
city
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"customerId": "gid://shopify/Customer/624407574",
"addressId": "gid://shopify/MailingAddress/624407574?model_name=CustomerAddress"
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"customerId": "gid://shopify/Customer/624407574",
"addressId": "gid://shopify/MailingAddress/624407574?model_name=CustomerAddress"
}
Response
JSON{
"customerUpdateDefaultAddress": {
"customer": {
"id": "gid://shopify/Customer/624407574",
"defaultAddress": {
"id": "gid://shopify/MailingAddress/624407574?model_name=CustomerAddress",
"address1": "124 Amoebobacterieae St",
"city": "Ottawa"
}
},
"userErrors": []
}
}