Anchor to section titled 'undefined'

customerUpdateDefaultAddress
mutation

Requires write_customers access scope. Also: User needs customers permission.

Updates a customer's default address.


Anchor to addressId
addressId
required

The ID of the customer's new default address.

Anchor to customerId
customerId
required

The ID of the customer whose default address is being updated.


Was this section helpful?

The customer whose address was updated.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
Copy
mutation customerUpdateDefaultAddress($addressId: ID!, $customerId: ID!) {
  customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
    customer {
      defaultAddress {
        id
      }
    }
    userErrors {
      message
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation customerUpdateDefaultAddress($addressId: ID!, $customerId: ID!) { customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) { customer { defaultAddress { id } } userErrors { message } } }",
 "variables": {
    "customerId": "gid://shopify/Customer/624407574",
    "addressId": "gid://shopify/MailingAddress/1053317286?model_name=CustomerAddress"
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation customerUpdateDefaultAddress($addressId: ID!, $customerId: ID!) {
    customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
      customer {
        defaultAddress {
          id
        }
      }
      userErrors {
        message
      }
    }
  }`,
  {
    variables: {
      "customerId": "gid://shopify/Customer/624407574",
      "addressId": "gid://shopify/MailingAddress/1053317286?model_name=CustomerAddress"
    },
  },
);

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 customerUpdateDefaultAddress($addressId: ID!, $customerId: ID!) {
    customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
      customer {
        defaultAddress {
          id
        }
      }
      userErrors {
        message
      }
    }
  }
QUERY

variables = {
  "customerId": "gid://shopify/Customer/624407574",
  "addressId": "gid://shopify/MailingAddress/1053317286?model_name=CustomerAddress"
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation customerUpdateDefaultAddress($addressId: ID!, $customerId: ID!) {
      customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
        customer {
          defaultAddress {
            id
          }
        }
        userErrors {
          message
        }
      }
    }`,
    "variables": {
      "customerId": "gid://shopify/Customer/624407574",
      "addressId": "gid://shopify/MailingAddress/1053317286?model_name=CustomerAddress"
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation customerUpdateDefaultAddress($addressId: ID!, $customerId: ID!) {
    customerUpdateDefaultAddress(addressId: $addressId, customerId: $customerId) {
      customer {
        defaultAddress {
          id
        }
      }
      userErrors {
        message
      }
    }
  }
QUERY;

$variables = [
  "customerId" => "gid://shopify/Customer/624407574",
  "addressId" => "gid://shopify/MailingAddress/1053317286?model_name=CustomerAddress",
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "customerId": "gid://shopify/Customer/624407574",
  "addressId": "gid://shopify/MailingAddress/1053317286?model_name=CustomerAddress"
}
Hide code
Response
JSON
{
  "customerUpdateDefaultAddress": {
    "customer": {
      "defaultAddress": {
        "id": "gid://shopify/MailingAddress/1053317286?model_name=CustomerAddress"
      }
    },
    "userErrors": []
  }
}