Why I am getting GraphQL error: The billing address must contain either “customer_address_id” or “address”?

magento.stackexchange https://magento.stackexchange.com/questions/321373

Question

I am using magento graphQL api to build mobile app of magento site. In checkout process we have to set billing address. So I used one of mutation setBillingAddressOnCart to set billing address on checkout. And I want to use billing address same as shipping so I passed same_as_shipping: true in billing_address. But when it's run, I am getting error :

Error: GraphQL error: The billing address must contain either "customer_address_id" or "address".

Here is mutation I used to set billing address :

  mutation setBillingAddressSameAsShipping($cartId: String!) {
    setBillingAddressOnCart(input: { cart_id: $cartId, billing_address: { same_as_shipping: true } }) {
      cart {
        id
        email
        shipping_addresses {
          selected_shipping_method {
            method_code
            method_title
          }
        }
      }
    }
  }

Please anyone can tell me why I am getting this error ? Why I have to pass customer_address_id even if I want to use billing address same as shipping ? And if I customer_address_id is really required than what for guest user ?

Was it helpful?

Solution

I have checked your mutation request parameters. First of all, this mutation is all about to set billing address for your specific quote (cart). So either you need to pass "customer_address_id (i.e. shipping address id in case you want to assign ready made address which is already saved before) or address fields (if you are creating a new address now).

Devdocs Reference :

enter image description here

I know that you need to just copy the shipping address into billing address. But GraphQL need either shipping address id which needed to copy into billing address or the whole new address object. It is not that smart that it will pick up your shipping address and copy into billing address automatically.

For guest user you need to pass the whole address object as below:

mutation {
  setBillingAddressOnCart(
    input: {
      cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"
      billing_address: {
        address: {
          firstname: "Bob"
          lastname: "Roll"
          company: "Magento"
          street: ["Magento Pkwy", "Main Street"]
          city: "Austin"
          region: "TX"
          postcode: "78758"
          country_code: "US"
          telephone: "8675309"
          save_in_address_book: true
        }
        same_as_shipping: false
      }
    }
  ) {
    cart {
      billing_address {
        firstname
        lastname
        company
        street
        city
        region{
          code
          label
        }
        postcode
        telephone
        country{
          code
          label
        }
      }
    }
  }
}

I hope I made clear your doubts. Still, if you have any queries feel free to ask!

Thanks,

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top