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 limit is 250 metafields for a single cart.
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
- GraphQL Storefront API overview
- GraphQL Storefront API: Carts and Checkout
- Authenticating requests to the GraphQL Storefront API
- Authentication and Example Requests: BigCommerce-generated JWTs
- GraphQL Storefront Playground
Did you find what you were looking for?