Legacy referrals
Legacy API endpoints for referral codes, applying codes, stats and rewards in projects where BillStack runs checkout.
Legacy (v1) API. This page describes the Stripe-first legacy referral routes. They stay supported for existing integrations but are frozen: new features ship only in v2. Prefer v2 for new work: Referrals.
These are the original by-external-id routes. They apply only to projects where BillStack runs checkout and entitlements (billingOwnership: "billstack", the default). They are not used in external mode. All referral endpoints are project scoped and require a private API key or an authenticated dashboard session with project access.
These routes belong to projects where BillStack runs checkout and entitlements. In that mode a referral starts pending, becomes refund_period after the referee's payment activates an entitlement, and is rewarded with bonus months after refundWindowDays. Do not use them for a project in external mode.
Get or create code
GET or POST /api/billstack/teams/{teamId}/projects/{projectId}/referrals/code/by-external-id/{externalId}Optional body for POST:
{
"email": "user@example.com",
"phone": "+14155550123",
"name": "Example User"
}Response:
{
"code": {
"id": "rcode_...",
"projectId": "proj_...",
"customerId": "pc_...",
"code": "ABCD1234",
"usageCount": 0,
"totalCreditsEarned": 0,
"totalMonthsEarned": 0,
"isActive": true,
"createdAt": "2026-01-01T00:00:00.000Z",
"updatedAt": "2026-01-01T00:00:00.000Z"
}
}The short shareable code is code.code; the rest of the object is the full referral code row (created on first call, reused on subsequent calls).
Errors
| Status | Meaning |
|---|---|
400 | Referrals are not enabled — the project's referral config is missing or disabled |
Apply code
POST /api/billstack/teams/{teamId}/projects/{projectId}/referrals/apply/by-external-idBody:
{
"code": "ABCD1234",
"refereeExternalId": "new_user_456",
"email": "new@example.com",
"phone": "+14155550124",
"name": "New User"
}Response (201 Created) is the full referral row:
{
"referral": {
"id": "ref_...",
"projectId": "proj_...",
"referralCodeId": "rcode_...",
"referrerCustomerId": "pc_...",
"refereeCustomerId": "pc_...",
"status": "pending",
"referrerCreditAmount": 500,
"refereeCreditAmount": 500,
"rewardMonths": 1,
"provider": null,
"providerSubscriptionId": null,
"providerPaymentId": null,
"providerEventId": null,
"convertedAt": null,
"eligibleAt": null,
"rewardedAt": null,
"reversedAt": null,
"expiresAt": "2026-01-31T00:00:00.000Z",
"createdAt": "2026-01-01T00:00:00.000Z",
"updatedAt": "2026-01-01T00:00:00.000Z"
}
}Errors
| Status | Meaning |
|---|---|
400 | code and refereeExternalId are required — request body is missing required fields |
400 | Invalid referral code — code not found, inactive, wrong project, or the referrer applying their own code |
Stats
GET /api/billstack/teams/{teamId}/projects/{projectId}/referrals/stats/by-external-id/{externalId}Use this endpoint for ambassador dashboards and account pages.
Response:
{
"totalReferrals": 12,
"registeredReferrals": 3,
"onTrial": 2,
"referralsUsed": 5,
"inRefundPeriod": 1,
"canceledReferrals": 1,
"monthsEarned": 5
}onTrial is always 0; no referral status represents a trial. The field is kept for compatibility. canceledReferrals counts cancelled and reversed referrals.
Process rewards
POST /api/billstack/teams/{teamId}/projects/{projectId}/referrals/rewards/processScans referrals that are past their refund window and claims eligible rewards. Requires project-admin dashboard access or a private API key.
Rewards are not processed automatically — integrators should call this endpoint periodically (for example, a daily cron job) to grant earned referral rewards.
Optional body:
{
"limit": 100
}limit defaults to 100 and is capped at 500.
Response:
{
"scanned": 42,
"rewarded": 7
}