> ## Documentation Index
> Fetch the complete documentation index at: https://docs-test.rye.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# setCartAttributes

> 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="/docs/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="/docs/api-reference/carterror">[CartError!]!</a></>}>
  List of errors that occurred while setting cart attributes.
</ParamField>

***

### Example - request

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

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

***

### Example - response

```json theme={null}
{
  "data": {
    "setCartAttributes": {
      "userErrors": []
    }
  }
}
```

***

### Related mutations

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