PHP 7.3 reached end of support in December 2021 and Adobe Commerce 2.3.x reaches end of support in September 2022. You may want to consider planning your upgrade now to Adobe Commerce 2.4.x and PHP 7.4.x to help maintain PCI compliance.
createEmptyCart mutation
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
1
2
3
4
5
mutation {
createEmptyCart {
String
}
}
Example usage
Create a cart with a randomly-generated cart ID
Request:
1
2
3
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.
1
2
3
4
5
{
"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:
1
2
3
4
5
6
7
mutation {
createEmptyCart(
input: {
cart_id: "x2345678901234567890123456789012"
}
)
}
Response:
The mutation returns the same cart_id
.
1
2
3
4
5
{
"data": {
"createEmptyCart": "x2345678901234567890123456789012"
}
}
Input attributes
Attribute | Data Type | Description |
---|---|---|
cart_id |
String | An optional 32-character string |
Output attributes
The createEmptyCart
mutation returns the cart ID.
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. |