Skip to navigation

Metafields API Guides

GraphQL Storefront API: Cart Metafields

Working with cart metafields

Cart metafields let you add custom metadata to a cart to display product information. Cart metafields are key-value pairs. You can work with them using both the GraphQL Storefront API and the REST Management API.

Example queries and mutations

Query cart metafields

Example query: Get cart metafields
query getCartMetafields {
site{
cart{
metafields(namespace: "bc_storefront"){
edges{
node{
id
key
value
}
}
}
}
}
}

Create a cart metafield

The platform limits are as follows:

  • 10 metafields per client (with customer ID or without ID) per cart
  • 250 metafields in total for a single cart (e.g., 25 clients * 10 metafields)
Example mutation: Create a cart metafield
mutation createCartMetafield {
cart {
createCartMetafield(input:{
cartEntityId: "4a5fd706-beb9-41b5-9ac2-01593b471168"
data: {
key: "size"
value: "small"
}
}) {
metafield {
id
entityId
key
value
}
errors {
...on Error {
message
}
}
}
}
}

Update a cart metafield

Example mutation: Update a cart metafield
mutation updateCartMetafield {
cart {
updateCartMetafield(input:{
cartEntityId: "4a5fd706-beb9-41b5-9ac2-01593b471168"
metafieldEntityId:53
data: {
key: "Size",
value: "medium"
}
}) {
metafield {
id
entityId
key
value
}
errors {
...on Error {
message
}
}
}
}
}

Delete a cart metafield

Example mutation: Delete a cart metafield
mutation deleteCartMetafield {
cart {
deleteCartMetafield(input:{
cartEntityId: "4a5fd706-beb9-41b5-9ac2-01593b471168"
metafieldEntityId: 53
}) {
errors {
... on NotFoundError {
__typename
message
}
... on ValidationError {
__typename
message
path
}
... on NotAuthorisedError {
__typename
}
}
}
}
}

Resources

GraphQL documentation