> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: "setCartAttributes"
description: "Sets custom attributes on a cart."
---

Use this mutation to attach arbitrary key-value pairs to a cart. Attributes can be used to store additional metadata about the cart, such as custom order notes, referral sources, or customer preferences.

***

### Arguments

<ParamField path="id" type="ID!" required>
  The unique identifier of the cart to update.
</ParamField>

<ParamField path="attributes" type={<a href="/api-reference/attributeinput">[AttributeInput!]!</a>} required>
  A list of key-value pairs to set on the cart. Each attribute has a `key` and `value` field, both limited to 500 characters.
</ParamField>

***

### Returns

<ParamField path="SetCartAttributesResult.userErrors" type={<a href="/api-reference/carterror">[CartError!]!</a>}>
  List of errors that occurred while setting cart attributes.
</ParamField>

***

### Example - request

```json Query arguments
{
  "id": "{{cartId}}",
  "attributes": [
    {
      "key": "gift_message",
      "value": "Happy Birthday!"
    },
    {
      "key": "referral_source",
      "value": "instagram"
    }
  ]
}
```

```GraphQL GraphQL
mutation ($id: ID!, $attributes: [AttributeInput!]!) {
  setCartAttributes(id: $id, attributes: $attributes) {
    userErrors {
      code
      message
    }
  }
}
```

***

### Example - response

```json
{
  "data": {
    "setCartAttributes": {
      "userErrors": []
    }
  }
}
```

***

### Related mutations

* [`createCart`](/api-reference/createcart)
* [`updateCartBuyerIdentity`](/api-reference/updatecartbuyeridentity)


---

*Powered by [holocron.so](https://holocron.so)*
