Skip to main content

Update cart details

Use the updateCartItems and updateCart mutations to update details related to items in the cart or the whole cart itself. Updates can be performed at any point before purchase is completed.

Update cart items

Use the updateCartItems mutation to update the following fields of the items in an existing cart:

  • Subscription custom attribute fields values
  • Product fields
  • Units
  • pricingPlanId

You can update multiple items in the cart through a single request.

Mutation:

mutation updateCartItems($input: UpdateCartItemsInput!) {
updateCartItems(input: $input) {
cart {
id
buyerUser {
id
}
items {
id
customAttributes {
subscriptionCustomAttributes {
key
value
}
productFields {
key
value
}
}
}
}
}
userErrors {
... on UnitQuantityMinError {
__typename
message
path
}
... on UnitQuantityMaxError {
__typename
message
path
}
... on UnitQuantityIncrementError {
__typename
message
path
}
}

}

Sample arguments

{
"cartId": "65117cd8ce3df31e68af9446",
"locale": "en-US"
}

Sample arguments

{
"input":
"cartId": "65117cd8ce3df31e68af9446",
"items": [{
"id": "0d07cbaf-e6a0-4c41-a8b9-a86743753116",
"customAttributes": {
"subscriptionCustomAttributes": [
{
"key": "testID",
"value": [
"BD755"
]
}]},
"units": [
{
"unit": "LICENSE",
"quantity": "10"
}
]

}]
}
}

Sample output

"data": {
"updateCartItems": {
"cart": {
"id": "65117cd8ce3df31e68af9446",
"buyerUser": {
"id": "1b6a48ea-98f6-49c6-9544-c6bb6936556b"
},
"items": [
{
"id": "8dff5f47-60ed-40cf-9c29-133a52cf3d86",
"customAttributes": {
"subscriptionCustomAttributes": [
{
"key": "testID",
"value": [
"BD755"
]
}
],
"productFields": [
{
"key": "UserPrincipleName",
"value": [
"Ram"
]
}
]
}
}
]
}
}
userErrors: null
}}

Error handling:

The updateCartItems mutation returns errors if invalid data is provided as input. One or more of the following (see table below) userErrors are returned if invalid unit quantities are provided while updating the values.

Error codeDescriptionExample
UnitQuantityMinErrorThis error occurs if the unit quantity value provided is lesser than the minimum allowed value.json {"data": { "updateCartItems": {"cart": null, "userErrors": [{ "__typename":"UnitQuantityMinError", "message": "Minimum allowed value for unit: MEGABYTE of item with id: d1407aa6-d43c-4479-8043-15c9a956f399 is 0.5. Please provide value greater than or equal to 0.5.","path": ["input","items","0","units","2","quantity" ]},]}}
UnitQuantityMaxErrorThis error occurs if the unit quantity value provided is more than maximum allowed value.json{"data": {"updateCartItems": {"cart": null,"userErrors": [{ "__typename": "UnitQuantityMaxError","message": "Maximum allowed value for unit: USER_LICENSE of item with id: d1407aa6-d43c-4479-8043-15c9a956f399 is 9. Please provide value lesser than or equal to 9.", "path": ["input","items","0","units","2","quantity"]}]}}
UnitQuantityIncrementErrorThis error occurs if the unit quantity value provided is not in line with the increment value configured for the unit.json{"data": {"updateCartItems": { "cart": null,"userErrors": [{"__typename": "UnitQuantityIncrementError","message": "Only value in increments of 1 is allowed for unit: MEGABYTE of item with id: d1407aa6-d43c-4479-8043-15c9a956f399.", "path": ["input","items","0","units","1","quantity"]}]}}

Update cart

Use the updateCart to update data at the cart level. You can also update the purchase custom attribute field values that get stored at the cart level.

Mutation:

mutation updateCart($input: UpdateCartInput!) {
updateCart(input: $input) {
cart {
id
buyerUser {
id
}
customAttributes {
purchaseCustomAttributes {
key
value
}
}
items {
id
units {
unit
quantity
}
}
}
}
}

Sample arguments:

{
"input": {
"cartId": "65117cd8ce3df31e68af9446",
"customAttributes": {
"purchaseCustomAttributes": [
{
"key": "testPurchaseAttribute",
"value": [
"YY532"
]
}
]
}
}
}

Sample output:

{
"data": {
"updateCart": {
"cart": {
"id": "65117cd8ce3df31e68af9446",
"buyerUser": {
"id": "1b6a48ea-98f6-49c6-9544-c6bb6936556b"
},
"customAttributes": {
"purchaseCustomAttributes": [
{
"key": "testPurchaseAttribute",
"value": [
"YY532"
]
}
]
},
"items": [
{
"id": "8dff5f47-60ed-40cf-9c29-133a52cf3d86",
"units": [
{
"unit": "LICENSE",
"quantity": 10
}
]
}
]
}
}
}

Was this page helpful?