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_as_shipping attribute to true. Magento assigns the same address as the shipping address.

Syntax

1
2
3
4
5
6
7
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
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
        region {
          code
          label
        }
        postcode
        telephone
        country {
          code
          label
        }
      }
    }
  }
}

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
{
  "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"
            }
          }
        ]
      }
    }
  }
}

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

Cart query output provides more information about the Cart object.

Errors

Error Description
Could not find a address with ID "XXX" The specified input.shipping_addresses.customer_address_id value does not exist in the customer_address_entity database table.
Could not find a cart with ID "XXX" The specified cart_id value does not exist in the quote_id_mask database table.
Current customer does not have permission to address with ID "XXX" The specified address ID in the input.shipping_addresses.customer_address_id argument belongs to another customer.
Required parameter "cart_id" is missing. The value specified in the cart_id argument is empty.
Required parameter "shipping_addresses" is missing The shipping_addresses argument is empty.
The Cart includes virtual product(s) only, so a shipping address is not used. You do not need to specify a shipping address because virtual products are not delivered.
The current customer isn't authorized. The current customer is not currently logged in, or the customer’s token does not exist in the oauth_token table.
The current user cannot perform operations on cart "XXX" An unauthorized user (guest) tried to update a shipping address of a customer’s cart, or an authorized user (customer) tried to update the shipping address of another customer’s cart.
The shipping address cannot contain "customer_address_id" and "address" at the same time. Specify either the ID of the existing customer’s address in the input.shipping_addresses.customer_address_id argument or a new customer’s address in the input.shipping_addresses.address argument (but not both).
You cannot specify multiple shipping addresses. You cannot specify more than one customer’s address in the input.shipping_addresses.address argument.