Backfill Historical Data (legacy)
Sync existing Stripe customers, products, and subscriptions into BillStack.
Legacy (v1) API, no v2 equivalent yet. This page describes the Stripe-first legacy API. It is still supported and is not replaced by a v2 route.
Use this guide when you already have Stripe data and need BillStack to mirror it before cutover.
What backfill does
Backfill copies existing Stripe data into BillStack's isolated team schema:
- Customers, products, prices, subscriptions
- Invoices and charges
After backfill, webhooks keep the mirror in sync automatically.
Trigger a full backfill
Dashboard
- Open Team Settings > Stripe Connection
- Click Sync Data / Backfill
- Wait for sync to complete
API
curl -X POST "https://billing.w3dev.app/api/billstack/teams/{teamId}/stripe/backfill" \
-H "Content-Type: application/json" \
-H "Cookie: <session-cookie>"This enqueues the sync as a background job (via Inngest) and returns immediately:
{
"queued": true,
"mode": "fresh",
"message": "Stripe backfill started in the background."
}Status code 202 means the job was queued, not that the sync finished. Poll /stripe/backfill/progress to watch it complete.
| Parameter | Type | Description |
|---|---|---|
mode | "fresh" | "resume" | fresh (default) wipes existing checkpoints and restarts every requested entity from scratch. resume skips entities already marked done and continues the rest. |
confirm | boolean | Required when mode is fresh (or omitted) and a sync is already syncing for this team. Without it the request is rejected with 409. |
objects | string[] | Entity types to sync. Omit for all types. |
createdAfter | string | ISO 8601 date. Only sync objects created after this date. |
If a sync is already in progress and you POST again with mode: "fresh" (the default) and no confirm, the API returns 409:
{
"error": "A sync is already in progress.",
"hint": "Send { \"mode\": \"fresh\", \"confirm\": true } to restart from scratch, or { \"mode\": \"resume\" } to continue where it left off.",
"syncStatus": "syncing"
}Selective backfill
Sync only specific entity types or filter by creation date. objects must use the plural entity names below — singular names (e.g. "customer") are silently ignored and that entity is skipped:
curl -X POST "https://billing.w3dev.app/api/billstack/teams/{teamId}/stripe/backfill" \
-H "Content-Type: application/json" \
-H "Cookie: <session-cookie>" \
-d '{
"objects": ["customers", "products", "prices", "subscriptions"],
"createdAfter": "2025-01-01T00:00:00Z"
}'Valid objects values, in sync order:
productscustomerspricessubscriptionsinvoiceschargespayment_intentscheckout_sessionspayment_methodsbalance_transactionspayouts
| Parameter | Type | Description |
|---|---|---|
objects | string[] | Entity types to sync (plural, see list above). Omit for all types |
createdAfter | string | ISO 8601 date. Only sync objects created after this date |
Assign customers to projects
After backfill, Stripe data lives in the team schema but customers are not yet assigned to projects:
- Create a project in BillStack for each SaaS product
- Create customers via the API with
externalIdmapping:
curl -X POST \
"https://billing.w3dev.app/api/billstack/teams/{teamId}/projects/{projectId}/customers" \
-H "Authorization: Bearer bs_..." \
-H "Content-Type: application/json" \
-d '{
"externalId": "user_123",
"email": "existing-customer@example.com",
"name": "Jane Doe"
}'Monitor sync status
curl "https://billing.w3dev.app/api/billstack/teams/{teamId}/stripe/status" \
-H "Cookie: <session-cookie>"syncStatus values: pending, syncing, synced, failed.
Per-entity progress
For live, per-entity checkpoint data (useful for a progress bar), poll:
curl "https://billing.w3dev.app/api/billstack/teams/{teamId}/stripe/backfill/progress" \
-H "Cookie: <session-cookie>"{
"syncStatus": "syncing",
"entities": [
{
"entity": "products",
"status": "done",
"itemsSynced": 42,
"errorCount": 0
},
{
"entity": "customers",
"status": "in_progress",
"itemsSynced": 1300,
"errorCount": 2
}
],
"summary": {
"total": 11,
"done": 1,
"inProgress": 1,
"pending": 9,
"totalItemsSynced": 1342,
"totalErrors": 2
}
}Each entity's status is one of pending, in_progress, or done.
Idempotency
The sync engine uses upserts, so each individual page is safe to replay. However, rerunning the top-level backfill request is not unconditionally safe:
- If a sync is already
syncingand you POST again with the defaultmode: "fresh", the request is rejected with409unless you passconfirm: true— this guards against accidentally wiping in-progress checkpoints. - To safely re-run a backfill that's still in progress (or retry after a failure) without restarting from scratch, use
mode: "resume"— it skips entities already markeddoneand continues the rest. - Once a sync has finished (
syncStatus: "synced"or"failed"), a plainmode: "fresh"POST is accepted and starts over from the beginning.
Next step
Continue with Migrate from Stripe to replace local Stripe SDK calls.