CreateGuestCartMutation
Description
Creates a new cart for a guest user and returns the cart ID. This is typically the first mutation you would call when implementing a shopping cart for non-logged-in users.
Endpoint
mutation createGuestCart {
createGuestCart {
cartId
}
}
Arguments
This mutation does not accept any arguments.
Return Values
The mutation returns a QuoteType object with the following fields:
| Field | Type | Description |
|---|---|---|
| cartId | String | The unique identifier for the newly created cart. This ID should be stored and used in subsequent cart operations. |
Usage Example
mutation {
createGuestCart {
cartId
}
}
Example Response
{
"data": {
"createGuestCart": {
"cartId": "abc123def456"
}
}
}
Notes
- The cart ID returned by this mutation should be stored client-side (e.g., in localStorage or a cookie) for use in subsequent cart operations.
- This cart is associated with a guest user. If you need to create a cart for a logged-in customer, use the
createCustomerCartmutation instead. - Guest carts may have different capabilities or limitations compared to customer carts, depending on your store configuration.
- The cart will remain active until it is converted to an order or expires based on your store's cart lifetime settings.