Update cart details
Use the mutations described in this topic to make updates to cart items and specific custom attributes at both cart and cart item level.
Update cart items
Use the updateCartItems mutation to modify details of items in your cart. You can also update the following item level fields before completing a purchase.
- Units
-
pricingPlanId
You can update single or multiple items in the cart through a single request.
Mutation:
mutation updateCartItems($input: UpdateCartItemsInput!) {
updateCartItems(input: $input) {
cart {
id
items {
pricingPlan {
id
}
units {
quantity
unit
}
}
}
}
userErrors {
... on UnitQuantityMinError {
__typename
message
path
}
... on UnitQuantityMaxError {
__typename
message
path
}
... on UnitQuantityIncrementError {
__typename
message
path
}
}
}
Sample arguments
{
"input": {
"cartId": "668be7d341fe9e7a04bbbb53",
"items": [{
"id": "33e7ac1a-fcaf-484c-9d17-eccb77153152",
"units": {
"quantity": "3",
"unit": "USER"
},
"pricingPlanId": "ae2665ca-84fa-4dd4-ac61-0c36fe8a1fe1"
}]
}
}
Sample output
{
"data": {
"updateCartItems": {
"cart": {
"id": "668be7d341fe9e7a04bbbb53",
"items": [
{
"pricingPlan": {
"id": "ae2665ca-84fa-4dd4-ac61-0c36fe8a1fe1"
},
"units": [
{
"quantity": 3,
"unit": "USER"
}
]
}
]
}
}
}
}
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 code | Description | Example |
---|---|---|
UnitQuantityMinError | This 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" ]},]}} |
UnitQuantityMaxError | This 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"]}]}} |
UnitQuantityIncrementError | This 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 custom attributes
Use this mutation to update custom attribute values cart and cart item level. You can use this mutation to update the following fields at any point before purchase completion:
- Subscription custom attribute fields values
- Product field values
- Purchase custom attribute fields values
Subscription custom attributes and Product fields are item level fields whereas Purchase custom attribute fields are cart level fields.
Mutation:
mutation updateCartCustomAttributes($input: UpdateCartCustomAttributesInput!) {
updateCartCustomAttributes(input: $input) {
cart {
id
customAttributes {
purchaseCustomAttributes {
key
value
}
}
items {
id
customAttributes {
subscriptionCustomAttributes {
key
value
}
productFields {
key
value
}
}
}
}
}
}
Sample arguments
{
"input": {
"cartId": "668be7d341fe9e7a04bbbb53",
"customAttributes": {
"purchaseCustomAttributes": [{
"key": "testID",
"value": "test purchase value"
}]
},
"items": [{
"id": "33e7ac1a-fcaf-484c-9d17-eccb77153152",
"customAttributes": {
"subscriptionCustomAttributes": [{
"key": "testID",
"value": "test subscription value"
}],
"productFields": [
{ "key": "test", "value": "test value 1" },
{ "key": "dropdown", "value": "dropdownvalue1" }
]
}
}]
}
}
Sample response
{
"data": {
"updateCartCustomAttributes": {
"cart": {
"items": [
{
"id": "33e7ac1a-fcaf-484c-9d17-eccb77153152",
"customAttributes": {
"subscriptionCustomAttributes": [
{
"key": "testID",
"value": [
"test subscription value"
]
}
],
"productFields": [
{
"key": "test",
"value": [
"test value 1"
]
},
{
"key": "dropdown",
"value": [
"dropdownvalue1"
]
}
]
}
}
],
"customAttributes": {
"purchaseCustomAttributes": [
{
"key": "testID",
"value": [
"test purchase value"
]
}
]
}
}
}
}
}
Common errors
For information on some of the common errors related to this mutation, refer to the section on Error handling.
Was this page helpful?
Tell us more…
Help us improve our content. Responses are anonymous.
Thanks
We appreciate your feedback!