setShippingAddressesOnCart mutation

The setShippingAddressesOnCart mutation sets one or more shipping addresses on a specific cart. The shipping address does not need to be specified in the following circumstances:

  • The cart contains only virtual items
  • When you defined the billing address, you set the same_for_shipping attribute to true. Magento assigns the same address as the shipping address.

Syntax

mutation: {setShippingAddressesOnCart(input: SetShippingAddressesOnCartInput) {SetShippingAddressesOnCartOutput}}

Example usage

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
mutation {
  setShippingAddressesOnCart(
    input: {
      cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"
      shipping_addresses: [
        {
          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: false
          }
        }
      ]
    }
  ) {
    cart {
      shipping_addresses {
        firstname
        lastname
        company
        street
        city
        postcode
        telephone
      }
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
  "data": {
    "setShippingAddressesOnCart": {
      "cart": {
        "shipping_addresses": [
          {
            "firstname": "Bob",
            "lastname": "Roll",
            "company": "Magento",
            "street": [
              "Magento Pkwy",
              "Main Street"
            ],
            "city": "Austin",
            "postcode": "78758",
            "telephone": "8675309"
          }
        ]
      }
    }
  }
}

Input attributes

The top-level SetShippingAddressesOnCartInput object is listed first. All child objects are listed in alphabetical order.

SetShippingAddressesOnCartInput object

Attribute Data Type Description
cart_id String! The unique ID that identifies the customer’s cart
shipping_addresses ShippingAddressInput! The shipping address for a specific cart

CartAddressInput object

Attribute Data Type Description
city String! The city specified for the billing or shipping address
company String The company specified for the billing or shipping address
country_code String! The country code and label for the billing or shipping address
firstname String! The customer’s first name
lastname String! The customer’s last name
postcode String The postal code for the billing or shipping address
region String The region code and label for the billing or shipping address
save_in_address_book Boolean! Specifies whether to save the address (True/False)
street [String]! An array containing the street for the billing or shipping address
telephone String The telephone number for the billing or shipping address

ShippingAddressInput object

Attribute Data Type Description
address CartAddressInput The shipping address for the cart
customer_address_id Int The unique ID that identifies the customer’s address
customer_notes String Text provided by the customer

Output attributes

The SetShippingAddressOnCartOutput object contains the Cart object.

Attribute Data Type Description
cart Cart! Describes the contents of the specified shopping cart

Cart object

Attribute Data Type Description
applied_coupon AppliedCoupon Deprecated. Use applied_coupons instead
applied_coupons [AppliedCoupon] An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code
applied_gift_cards [AppliedGiftCard] An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module
applied_store_credit AppliedStoreCredit Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module
available_payment_methods [AvailablePaymentMethod] Available payment methods
billing_address BillingCartAddress Contains the billing address specified in the customer’s cart
email String The customer’s email address
id ID! The ID of the cart
is_virtual Boolean Indicates whether the cart contains only virtual products
items [CartItemInterface] Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses [ShippingCartAddress]! Contains one or more shipping addresses

Cart query output provides more information about the Cart object.