data-src=../../../../includes/paas-only.md

createEmptyCart mutation

data-variant=warning
data-slots=text
The createEmptyCart mutation has been deprecated. Use the createGuestCart mutation instead.

The createEmptyCart mutation creates an empty shopping cart for a guest or logged in customer. You can allow the system to generate a cart ID, or assign a specific ID.

If you are creating a cart for a logged in customer, you must include the customer's authorization token in the header of the request.

Syntax

mutation {
  createEmptyCart {
    String
  }
}

Reference

The createEmptyCart reference provides detailed information about the types and fields defined in this mutation.

Example usage

Create a cart with a randomly-generated cart ID

Request:

mutation {
  createEmptyCart
}

Response:

The response is the cart ID, which is sometimes called the quote ID. The remaining examples in this topic will use this cart ID.

{
  "data": {
    "createEmptyCart": "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"
  }
}

Create an empty cart with an assigned cart ID

You can also create an empty cart with a specified cart_id.

Request:

mutation {
  createEmptyCart(
    input: {
      cart_id: "x2345678901234567890123456789012"
    }
  )
}

Response:

The mutation returns the same cart_id.

{
  "data": {
    "createEmptyCart": "x2345678901234567890123456789012"
  }
}

Errors

Error
Description
Cart with ID "XXX" already exists.
The specified cart ID was previously used to create a cart.
Cart ID length should to be 32 symbols.
The cart ID is not the required length.