setCustomAttributesOnCart mutation
data-src=/_includes/graphql/custom-attribute-availability.md
The setCustomAttributesOnCart mutation sets custom attributes on a cart. The mutation accepts a cart ID and an array of custom attribute key/value pairs. It returns the updated cart. All ID values are treated as strings.
When the quote is converted to an order, the custom attributes are copied to the order.
To remove a custom attribute, rerun the mutation without the previously applied custom attribute.
data-variant=info
data-slots=text
You can apply custom attributes directly to cart items when adding products with the
addProductsToCart mutation mutation by passing an array of attribute code/value pairs in CartItemInput.custom_attributes. This feature is automatically available on Adobe Commerce as a Cloud Service (SaaS). On Adobe Commerce on-premises and on cloud infrastructure (PaaS), install version 0.7.0 or later of the magento/out-of-process-custom-attributes module module to use it.Syntax
mutation {
setCustomAttributesOnCart(
input: CartCustomAttributesInput
){
AddCustomAttributesToCartItemOutput
}
}
Reference
The setCustomAttributesOnCart reference provides detailed information about the types and fields defined in this mutation.
Example usage
The following mutation sets custom attributes on a cart with the specified ID. The custom attributes are provided as an array of key-value pairs.
Request:
mutation {
setCustomAttributesOnCart(
input: {
cart_id: "8k0Q4MpH2IGahWrTRtqM61YV2MtLPApz"
custom_attributes: [
{
attribute_code: "custom_attribute_1",
value: "value1"
}
{
attribute_code: "custom_attribute_2",
value: "value2"
}
]
}
) {
cart {
id
custom_attributes {
attribute_code
value
}
}
}
}
Response:
{
"data": {
"setCustomAttributesOnCart": {
"cart": {
"id": "8k0Q4MpH2IGahWrTRtqM61YV2MtLPApz",
"custom_attributes": [
{
"attribute_code": "custom_attribute_1",
"value": "value1"
},
{
"attribute_code": "custom_attribute_2",
"value": "value2"
}
]
}
}
}
}