setGuestEmailOnCart mutation

For guest customers, you must assign an email to the cart before you place the order.

A logged-in customer specifies an email address when they create an account. Therefore, you can place the order without explicitly setting the email.

Syntax

mutation: {setGuestEmailOnCart(input: SetGuestEmailOnCartInput): {SetGuestEmailOnCartOutput}}

Example usage

Request:

1
2
3
4
5
6
7
8
9
10
11
12
mutation {
  setGuestEmailOnCart(
    input: {
      cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"
      email: "jdoe@example.com"
    }
  ) {
    cart {
      email
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
{
  "data": {
    "setGuestEmailOnCart": {
      "cart": {
        "email": "jdoe@example.com"
      }
    }
  }
}

Input attributes

The SetGuestEmailOnCartInput object must contain the following attributes.

Attribute Data Type Description
cart_id String! The unique ID that identifies the customer’s cart
email String! The guest user’s email

Output attributes

The SetGuestEmailOnCartOutput 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.

Errors

Error Description
Could not find a cart with ID "XXX" The ID specified in the cart attribute does not exist.
Invalid email format The value specified in the email attribute has an incorrect format.
Required parameter "cart_id" is missing The cart_id attribute was omitted or contains an empty value.
Required parameter "email" is missing The email attribute was omitted or contains an empty value.
The current user cannot perform operations on cart "XXX" An unauthorized user (guest) tried to set the email address on the customer’s cart.
The request is not allowed for logged in customers An authorized user (customer) is not allowed to use the setGuestEmailOnCart mutation.