---
title: "One-off: NULL stale stripe_customer_id rows that don't exist under the current key"
method: POST
path: "/api/v1/admin/billing/reconcile-stripe-customers"
tags: ["admin"]
---

# One-off: NULL stale stripe_customer_id rows that don't exist under the current key

`POST /api/v1/admin/billing/reconcile-stripe-customers`

## Request

- Base URL: `https://api.badgeia.com`
- URL: `https://api.badgeia.com/api/v1/admin/billing/reconcile-stripe-customers`
- Auth: none declared

Bulk-clean ``stripe_customer_id`` rows orphaned by the test→live key flip.

ROAD-002 §WP-A task 4. When the prod Stripe key flipped from test to live,
every ``stripe_customer_id`` minted under the test key became "No such
customer" under the live key — a 400→503 on that user's next checkout. The
checkout handler now self-heals lazily (null + recreate + retry once), so
this endpoint is the *proactive* counterpart: verify each stored customer
against the current key and NULL the ones Stripe no longer knows.

Only rows Stripe positively reports as GONE (404) are cleared. Any
indeterminate signal (network error, rate-limit, unexpected status) leaves
the row untouched — we never destroy a mapping on an ambiguous answer.

Authorization:
    - Anonymous → 401 (auth dep on ``require_admin``).
    - Authenticated non-admin → 403 (``require_admin``).
    - Admin (email in ``ADMIN_EMAILS``) → 200.

Flag gate (rule #4): 404 when ``ADMIN_DASHBOARD_ENABLED`` is off, so the
whole ``/admin/*`` surface stays uniformly gated.

503 "Stripe not configured" (Sentry-allowlisted) when no key is set.

Response (counts only — never an email or a customer id):
    {"dry_run": bool, "scanned": int, "stale": int, "cleared": int,
     "indeterminate": int}

## Query parameters

- `dry_run` boolean: Preview counts without writing (default).

## Response `200`

Successful Response

- object

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/badgeia/apis/badge.md) · [All operations](https://skmtc.dev/badgeia/apis/badge/llms.txt) · [OpenAPI document](https://skmtc.dev/badgeia/apis/badge/revisions/7e7f7fee8b77?raw)
