This is a beta release of documentation for Magento 2.4, published for previewing soon-to-be-released functionality. Content in this version is subject to change. Links to the v2.4 code base may not properly resolve until the code is officially released.

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
36
37
38
39
40
41
42
43
44
45
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
          },
          pickup_location_code: "txspeqs"
        }
      ]
    }
  ) {
    cart {
      shipping_addresses {
        firstname
        lastname
        company
        street
        city
        region {
          code
          label
        }
        postcode
        telephone
        country {
          code
          label
        }
        pickup_location_code
      }
    }
  }
}

Response:

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
{
  "data": {
    "setShippingAddressesOnCart": {
      "cart": {
        "shipping_addresses": [
          {
            "firstname": "Bob",
            "lastname": "Roll",
            "company": "Magento",
            "street": [
              "Magento Pkwy",
              "Main Street"
            ],
            "city": "Austin",
            "region": {
              "code": "TX",
              "label": "Texas"
            },
            "postcode": "78758",
            "telephone": "8675309",
            "country": {
              "code": "US",
              "label": "US"
            },
            "pickup_location_code": "txspeqs"
          }
        ]
      }
    }
  }
}

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 Determines whether to save the address in the customer’s address book. The default value is true.
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
pickup_location_code String The code of the in-store pickup location where the customer will receive the order.

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
total_quantity Float! Total Quantity of products in the cart

Cart query output provides more information about the Cart object.