Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Hydrogen Customer Address Update Failed

Hydrogen Customer Address Update Failed

naitikkundalia
Shopify Partner
1 0 0

I am trying to update address using hydrogen. I can update default address but when i try to update another address it gives error.
My mutation:

 

 

export const UPDATE_ADDRESS_MUTATION = `#graphql
  mutation customerAddressUpdate(
    $address: CustomerAddressInput!
    $addressId: ID!
    $defaultAddress: Boolean=null
 ) {
    customerAddressUpdate(
      address: $address
      addressId: $addressId
      defaultAddress: $defaultAddress
    ) {
      customerAddress {
        id
      }
      userErrors {
        code
        field
        message
      }
    }
  }
`;

 

 


Default Address Update

 

 

const {data,errors} = await customerAccount.mutate(UPDATE_ADDRESS_MUTATION,{
          variables:{
            address:{
                zoneCode: "xxxx",
                territoryCode: "xxxx",
                firstName: "xxxx",
                lastName: "xxxx",
                address1: "xxxx",
                address2: "xxxx",
                city: "xxxx",
                zip: "xxxx",
                phoneNumber: "xxxx",
            },
            addressId:decodeURIComponent("xxxx")
            defaultAddress:true
          }
        })

 

 

In JSX Another Address

 

const {data,errors} = await customerAccount.mutate(UPDATE_ADDRESS_MUTATION,{
          variables:{
            address:{
                zoneCode: "xxxx",
                territoryCode: "xxxx",
                firstName: "xxxx",
                lastName: "xxxx",
                address1: "xxxx",
                address2: "xxxx",
                city: "xxxx",
                zip: "xxxx",
                phoneNumber: "xxxx",
            },
            addressId:decodeURIComponent("xxxx")
          }
        })

In another address I didnt pass defaultAddress or pass defaultAddress:null . So it is giving following error

CUSTOMER_ADDRESS_ALREADY_EXISTS

 

I tried to pass defaultAddress:false

DEMOTING_CUSTOMER_DEFAULT_ADDRESS_NOT_ALLOWED


So how to resolve it?

 

 

Reply 1 (1)

patrick_xin
Shopify Partner
1 0 1

I encountered the same problem, managed to solve it like this:

  const response = await shopifyCustomerFetch<updateCustomerAddressOperation>(
      {
        query: addressUpdateMutation,
        variables: {
          address,
          defaultAddress: defaultAddress ? true : null,
          addressId,
        },
      }
    );