Add Item

Use the addItem mutation to add new items to the cart.

Mutation

addItem(input: AddToCartInput!): Cart!

ArgumentsType
inputAddToCartInput!

The addItem mutation will always return the updated Cart object.

AddToCartInput!

You can add items to the cart at any time.

You must provide a unique id for cart items, otherwise you will overwrite any existing data, and increment existing quantities.

ArgumentTypeDescription
cartIdID!The id of the cart you are adding items to.
idID!The id of the item you are adding.
nameStringGive items a name.
descriptionStringGive items a description.
typeCartItemType = SKUSKU (default), TAX, SHIPPING.
images[String]Any URLs to images for the item.
priceInt!The item price in cents.
quantityInt = 1Quantity of items to add.
attributes[CustomAttributeInput]key/value custom properties.

If no cart exists with the id provided, one will be created for you.

Example

mutation {
  addItem(
    input: {
      cartId: "ck5r8d5b500003f5o2aif0v2b"
      id: "5e3293a3462051"
      name: "Full Logo Tee"
      description: "Purple Triblend / L"
      images: ["full-logo-tee.png"]
      price: 2000
      quantity: 10
    }
  ) {
    id
    isEmpty
    abandoned
    totalItems
    totalUniqueItems
    subTotal {
      formatted
    }
    items {
      id
      name
      description
      images
      unitTotal {
        amount
        formatted
      }
      lineTotal {
        amount
        formatted
      }
      quantity
    }
  }
}
{
  "data": {
    "addItem": {
      "id": "ck5r8d5b500003f5o2aif0v2b",
      "isEmpty": false,
      "abandoned": false,
      "totalItems": 10,
      "totalUniqueItems": 1,
      "subTotal": {
        "formatted": "$200.00"
      },
      "items": [
        {
          "id": "5e3293a3462051",
          "name": "Full Logo Tee",
          "description": "Purple Triblend / L",
          "images": ["full-logo-tee.png"],
          "unitTotal": {
            "amount": 2000,
            "formatted": "$20.00"
          },
          "lineTotal": {
            "amount": 20000,
            "formatted": "$200.00"
          },
          "quantity": 10
        }
      ]
    }
  }
}

CartItemType = SKU

The type value will change how cart totals are calculated.

SKU

...

TAX

...

SHIPPING

...