How to Integrate Chargebee with Your Headless CMS
Sync subscription plan copy, Chargebee price IDs, billing intervals, and checkout content from structured content to your Commerce experience.
What is Chargebee?
Chargebee is a subscription billing and revenue platform for companies that sell recurring products, including SaaS plans, memberships, usage-based packages, and digital subscriptions. Teams use it to handle product catalogs, invoices, payments, taxes, trials, coupons, dunning, and subscription lifecycle events. It sits in the recurring revenue category alongside tools such as Stripe Billing and Recurly, with a strong focus on subscription operations beyond the first checkout.
Why integrate Chargebee with a headless CMS?
Subscription commerce gets messy when your billing system and customer-facing content drift apart. A plan named “Pro Annual” in Chargebee might appear as “Growth yearly” on your pricing page, while a sales page references a retired trial length. That creates support tickets, failed checkouts, and awkward pricing reviews because nobody knows which system is correct.
Architecture overview
A typical Sanity and Chargebee integration starts with subscription plan content in the Content Lake. In Sanity Studio, you model fields such as plan name, slug, feature bullets, Chargebee item ID, Chargebee item price ID, item family ID, currency, price in cents, billing interval, trial days, and region. When an editor publishes a plan, a Sanity webhook can trigger on a GROQ filter like _type == "subscriptionPlan" and !(_id in path("drafts.**")). The webhook sends the document ID to a Sanity Function or an HTTPS middleware endpoint. That server-side code uses @sanity/client and GROQ to fetch exactly the fields Chargebee needs, including referenced feature groups or localized price copy. Then it calls Chargebee’s Product Catalog 2.0 API through the official Node SDK, usually item.create or item.update for the plan, and item_price.create or item_price.update for the billable price. The frontend still reads display content from Sanity, then starts checkout with Chargebee hosted pages or Chargebee.js using the synced item_price_id. The customer sees current plan copy, clicks a plan, and lands in a checkout flow tied to the right Chargebee billing object.
Common use cases
Subscription pricing pages
Publish plan names, feature tables, trial messaging, and Chargebee item_price_id values from one structured plan document.
Localized billing pages
Map region-specific copy, currencies, tax notes, and Chargebee price IDs for markets such as US, EU, and UK.
Campaign-specific offers
Connect Sanity campaign pages to Chargebee coupons, trial lengths, and hosted checkout links without hardcoding promo logic.
Plan packaging changes
Update feature bundles in Sanity and sync the matching Chargebee item metadata when product packaging changes.
Step-by-step integration
- 1
Set up Chargebee
Create a Chargebee site, choose Product Catalog 2.0, create an item family, and generate an API key from Settings > Configure Chargebee > API Keys and Webhooks. In your app, install the SDK with npm install chargebee.
- 2
Model subscription plans in Sanity Studio
Create a subscriptionPlan schema with fields for title, slug, feature bullets, chargebeeItemId, chargebeeItemPriceId, itemFamilyId, currencyCode, priceCents, billingPeriod, billingPeriodUnit, trialDays, and status. Keep billing identifiers separate from marketing copy so editors can work safely.
- 3
Create a publish trigger
Add a Sanity webhook with a GROQ filter for published subscriptionPlan documents. Send a small payload, for example { "documentId": _id }, to a Sanity Function or your own API route.
- 4
Fetch only the fields Chargebee needs
In the handler, use @sanity/client with GROQ to fetch the plan, its billing metadata, and any referenced feature labels needed for Chargebee metadata. Don’t send draft content or presentation-only fields to Chargebee.
- 5
Call Chargebee’s API
Use the Chargebee Node SDK to create or update the item and item price. Store stable IDs in Sanity, such as pro-monthly-usd, so your website, checkout flow, and billing catalog refer to the same object.
- 6
Test the buying path
Publish a test plan, confirm the item and item price in Chargebee, then open checkout from your frontend with the synced item_price_id. Test at least one monthly plan, one annual plan, one coupon, and one failed payment scenario.
How Sanity + Chargebee works
Build your Chargebee integration on Sanity
Sanity gives you the structured content foundation, real-time event system, and flexible APIs to connect subscription content with Chargebee billing workflows.
Start building free →CMS approaches to Chargebee
| Capability | Traditional CMS | Sanity |
|---|---|---|
| Subscription plan modeling | Plan content often lives inside pages, which makes billing IDs and feature tables hard to reuse across pricing pages, checkout, and support docs. | Schema-as-code lets you model plans, item families, item prices, features, regions, and campaign offers as connected content. |
| Chargebee catalog sync | Updates are often manual, or handled by custom scripts that parse page content before calling Chargebee. | Webhooks and Functions can trigger server-side sync on publish, then call Chargebee’s item and item_price APIs without a separate app. |
| Field-level control | The integration may receive whole pages, including layout fields Chargebee doesn’t need. | GROQ selects exactly the billing fields and referenced content needed for each Chargebee API call. |
| Multi-channel pricing content | Web pages are the primary output, so mobile apps and checkout flows often duplicate pricing copy. | One structured plan model can feed web, mobile, checkout, sales pages, documentation, and AI agents. |
| Editorial safety | Editors can accidentally change billing-related copy without updating the matching Chargebee object. | Sanity Studio can add field validation, role-based access, review tasks, and Content Releases before a plan syncs to Chargebee. |
Keep building
Explore related integrations to complete your content stack.
Sanity + Stripe
Pair structured product and pricing content with Stripe payments, checkout sessions, and customer billing flows.
Sanity + Shopify
Use Shopify for product inventory and checkout while Sanity runs product storytelling, landing pages, and buyer guides.
Sanity + Medusa
Build a custom commerce stack where Sanity structures product content and Medusa handles carts, orders, and commerce logic.