addToCart
Requires a customer (portal or buyer app) session.
Adds a variant to the cart, or raises its quantity if the line exists. Pass the cart revision you last saw, and an operation ID so a retry does not add twice.
Errors: a failed call returns a GraphQL errors entry, not a field on the result, and data may be null or partial. Read the entry's extensions.code and message; every shape and code is in the Error reference.
Example:
- GraphQL
- cURL
mutation AddToCart($input: AddToCartInput!) {
addToCart(input: $input) {
id
name
itemCount
revision
subtotal
updatedAt
items {
id
createdAt
acceptAlternativeIfUnavailable
baseUnitPrice
lineTotal
notes
}
}
}
curl -X POST "https://<api-host>/graphql" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
--data @- <<'EOF'
{
"query": "mutation AddToCart($input: AddToCartInput!) {\n addToCart(input: $input) {\n id\n name\n itemCount\n revision\n subtotal\n updatedAt\n items {\n id\n createdAt\n acceptAlternativeIfUnavailable\n baseUnitPrice\n lineTotal\n notes\n }\n }\n}",
"variables": {
"input": {
"productId": "id",
"quantity": 0,
"variantId": "id"
}
}
}
EOF
Variables:
{
"input": {
"productId": "id",
"quantity": 0,
"variantId": "id"
}
}
Response:
{
"data": {
"addToCart": {
"id": "id",
"name": "string",
"itemCount": 0,
"revision": 0,
"subtotal": 0,
"updatedAt": "2025-01-15T00:00:00Z",
"items": [
{
"id": "id",
"createdAt": "2025-01-15T00:00:00Z",
"acceptAlternativeIfUnavailable": true,
"baseUnitPrice": 0,
"lineTotal": 0,
"notes": "string"
}
]
}
}
}
addToCart(
input: AddToCartInput!
): CartType!
Arguments
addToCart.input ● AddToCartInput! non-null input
The product, variant, unit of measure and quantity, with optional notes, whether an alternative is accepted if it is out of stock, the expected cart revision and the operation ID.
Type
CartType object
The customer's cart.