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?

 

 

Replies 0 (0)