For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Dev Portal
DocsAPI ReferenceLearnCommunityChangelog
DocsAPI ReferenceLearnCommunityChangelog
  • Overview
    • Quick Start
    • Sandboxes
    • Tools & SDKs
    • Support
  • Docs
      • Getting Started
        • Overview
        • Localization
        • Metafields API Guides
        • Checkout URL
        • Optimized One-Page Checkout
        • Integrated Fastlane by PayPal
    • Archive
    • Closed Beta Programs
Dev Portal
LogoLogo
On this page
  • Working with cart metafields
  • Example queries and mutations
  • Query cart metafields
  • Create a cart metafield
  • Update a cart metafield
  • Delete a cart metafield
  • Resources
  • GraphQL documentation
DocsAdminCheckout & Cart

Metafields API Guides

Was this page helpful?
Previous

Localization

Next

Checkout URL

Built with

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

Request
Response
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)
Request
Response
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

Request
Response
Example mutation: Update a cart metafield
1mutation updateCartMetafield {
2 cart {
3 updateCartMetafield(input:{
4 cartEntityId: "4a5fd706-beb9-41b5-9ac2-01593b471168"
5 metafieldEntityId:53
6 data: {
7 key: "Size",
8 value: "medium"
9 }
10 }) {
11 metafield {
12 id
13 entityId
14 key
15 value
16 }
17 errors {
18 ...on Error {
19 message
20 }
21 }
22 }
23}
24}

Delete a cart metafield

Request
Response
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