Overview
Metadata provides simple, unstructured key-value storage on Spree resources — similar to Stripe’s metadata. It’s ideal for storing integration IDs, tracking data, or any arbitrary information that doesn’t need validation or admin UI. Metadata is write-only in the Store API — you can set it when creating or updating resources, but it is never returned in Store API responses. It is visible in Admin API responses for administrative use.For structured, type-safe custom attributes with admin UI support, use Metafields instead.
Store API
Cart creation
Set metadata when creating a new cart:Adding items
Set metadata when adding items to the cart:Updating items
Metadata is merged with existing values on update. Set a key tonull to remove it.
Updating carts
Admin API
Metadata is readable in Admin API responses on orders and line items:null.
Ruby / Backend
Reading and writing
Every model that includesSpree::Metadata has a metadata accessor (alias for private_metadata):
Querying
Merge semantics
Metadata updates use merge semantics — existing keys are preserved, new keys are added, and keys set tonull are removed. This matches Stripe’s behavior.
Metadata vs Metafields
| Metadata | Metafields | |
|---|---|---|
| Use case | Integration data, tracking, simple key-value | Structured custom attributes with admin UI |
| Validation | None | Type-specific (text, number, boolean, JSON) |
| Visibility | Write-only in Store API, readable in Admin API | Configurable (front-end, back-end, both) |
| Admin UI | Viewable in JSON preview | Full admin management |
| Schema | Schemaless JSON | Defined via MetafieldDefinitions |
| API pattern | Stripe-style flat key-value | Shopify-style typed resources |
When to use metadata
- Storing external system IDs (e.g., Stripe payment intent ID, ERP order ID)
- Tracking attribution data (UTM parameters, referral source)
- Passing context from the storefront that doesn’t need validation
- Any write-and-forget data that only needs to be read by backend systems
When to use metafields
- Custom product specifications shown to customers
- Admin-managed fields with validation
- Data that needs to appear in the admin UI
- Querying/filtering by custom attributes
Supported resources
All models that include theSpree::Metadata concern support metadata. This includes all core models: Orders, Line Items, Products, Variants, Taxons, Payments, Shipments, and more.
The Store API currently supports writing metadata on:
- Carts — on creation and update (
POST /api/v3/store/carts,PATCH /api/v3/store/carts/:id) - Items — on create and update (
POST/PATCH /api/v3/store/carts/:id/items)
Migration from public_metadata
Thepublic_metadata column is deprecated. Metadata is no longer returned in Store API responses. If you were using public_metadata for data that needs to be visible to customers, migrate to Metafields with display_on: 'both'.

