How To Billing Address in Cart By Using GraphQL in Magento 2.x / Adobe Commerce 2.x

The following below steps need to follow to add Billing address in Cart by using GraphQL in Magento 2.x / Adobe Commerce 2.x

Here, we are using the setBillingAddressesOnCart mutation to add a shipping address to the cart.

Below use for guest checkout & logged customer checkout, in case of logged checkout need to use customer authorization

Step [1] – Recommendation to use below syntax to Use Billing address in Cart

Here Using Postman

Syntax

mutation {
  setBillingAddressOnCart(
    input: {
      cart_id: "{ CART_ID }"
      billing_address: {
        address: {
          firstname: "John"
          lastname: "Doe"
          company: "Company Name"
          street: ["64 Strawberry Dr", "Beverly Hills"]
          city: "Los Angeles"
          region: "CA"
          region_id: 12
          postcode: "90210"
          country_code: "US"
          telephone: "123-456-0000"
          save_in_address_book: true
        }
      }
    }
  ) {
    cart {
      billing_address {
        firstname
        lastname
        company
        street
        city
        region{
          code
          label
        }
        postcode
        telephone
        country {
          code
          label
        }
      }
    }
  }
}

Step [2] – Put below Request

mutation {
  setBillingAddressOnCart(
    input: {
      cart_id: "{ CART_ID }"
      billing_address: {
        address: {
          firstname: "John"
          lastname: "Doe"
          company: "Company Name"
          street: ["64 Strawberry Dr", "Beverly Hills"]
          city: "Los Angeles"
          region: "CA"
          region_id: 12
          postcode: "90210"
          country_code: "US"
          telephone: "123-456-0000"
          save_in_address_book: true
        }
      }
    }
  ) {
    cart {
      billing_address {
        firstname
        lastname
        company
        street
        city
        region{
          code
          label
        }
        postcode
        telephone
        country {
          code
          label
        }
      }
    }
  }
}

Step [3] – Put below Output Response

{
    "data": {
        "setBillingAddressOnCart": {
            "cart": {
                "billing_address": {
                    "firstname": "John",
                    "lastname": "Doe",
                    "company": "Company Name",
                    "street": [
                        "64 Strawberry Dr",
                        "Beverly Hills"
                    ],
                    "city": "Los Angeles",
                    "region": {
                        "code": "CA",
                        "label": "California"
                    },
                    "postcode": "90210",
                    "telephone": "123-456-0000",
                    "country": {
                        "code": "US",
                        "label": "US"
                    }
                }
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *