# Referrals

> Referral codes, the program status and your own referral totals.

URL: https://renzo-digital.com/docs/resources/referrals

A customer with a username has a referral code. A friend who uses the code gets a discount on the first payment. The customer earns a reward when the friend subscribes. The program can be switched on or off by Renzo. Two checks are public. The rest need a token and a username.

## Endpoints

| Operation | What it does | Auth |
| --- | --- | --- |
| `GET /api/v1/referrals/program` | Say whether the program is on and what discount a friend gets. | None |
| `GET /api/v1/referrals/codes/{code}` | Check a code and read its discount. | None |
| `GET /api/v1/referrals/me` | Read your own code, link and totals. The code is made on the first read. | Token and username |
| `POST /api/v1/referrals/me/referrer` | Add the code of the friend who referred you: `{"code": "..."}`. Declares `Idempotency-Key`. | Token and username |

Without a username, the two token calls answer `409` [`profile_incomplete`](https://renzo-digital.com/docs/error-codes#profile_incomplete). See [Account](https://renzo-digital.com/docs/resources/account). `POST /api/v1/referrals/me/referrer` declares an `Idempotency-Key` header. Any mutating call accepts it. See [Idempotency](https://renzo-digital.com/docs/concepts/idempotency).

## Example: check a code, then read your totals

```bash tab="curl"
curl "$BASE/api/v1/referrals/codes/RENZO-A7K2"
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]

answer = requests.get(f"{BASE}/api/v1/referrals/codes/RENZO-A7K2")
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE } = process.env;

const answer = await fetch(`${BASE}/api/v1/referrals/codes/RENZO-A7K2`);
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

```json title="Response"
{
  "code": "RENZO-A7K2",
  "discount_percent": 20
}
```

```bash tab="curl"
curl "$BASE/api/v1/referrals/me" \
  -H "Authorization: Bearer $TOKEN"
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]
TOKEN = os.environ["TOKEN"]

answer = requests.get(
    f"{BASE}/api/v1/referrals/me",
    headers={"Authorization": f"Bearer {TOKEN}"},
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE, TOKEN } = process.env;

const answer = await fetch(`${BASE}/api/v1/referrals/me`, {
  headers: { Authorization: `Bearer ${TOKEN}` },
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

```json title="Response"
{
  "enabled": true,
  "code": "RENZO-A7K2",
  "link_path": "/r/RENZO-A7K2",
  "discount_percent": 20,
  "reward_days": 30,
  "hold_days": 14,
  "cap": 12,
  "totals": {
    "signed_up": 5,
    "subscribed": 2,
    "pending": 1,
    "next_reward_at": "2026-11-18T13:30:00Z",
    "earned": 1,
    "earned_credit_cents": 0,
    "left_this_year": 11
  },
  "has_referrer": false,
  "can_add_code": true,
  "my_reward": {
    "kind": "grant",
    "days": 30,
    "amount_cents": null,
    "applies_on": null
  }
}
```

## Rules and edge cases

- **Program off.** When the program is off, `GET /api/v1/referrals/program` answers `200` with `enabled: false`. `GET /api/v1/referrals/me` shows `enabled: false` and `code` and `link_path` as `null`. A code check answers `404` [`referral_code_not_found`](https://renzo-digital.com/docs/error-codes#referral_code_not_found).
- **Code check.** Case does not matter. An unknown, inactive or off-program code answers `404` [`referral_code_not_found`](https://renzo-digital.com/docs/error-codes#referral_code_not_found).
- **Rate limit.** The two public calls allow 30 requests per minute per IP address, each with its own bucket. More answers `429` [`rate_limited`](https://renzo-digital.com/docs/error-codes#rate_limited), with a `Retry-After` header. See [Rate limits](https://renzo-digital.com/docs/concepts/rate-limits).
- **Your link.** `link_path` is `/r/{code}` on the customer web host. Share the full link with friends.
- **Totals.** Friends are never named. `signed_up` counts friends who signed up with your code. `subscribed` counts those who paid a first invoice. `pending` is rewards on the way, and `next_reward_at` is when the next one is due. `earned` is rewards given, all time. `left_this_year` is how many rewards are still possible in the last 12 months, under `cap`.
- **Rewards.** A reward waits `hold_days` before it is given. `my_reward.kind` is `grant`, with `days` of Premium, or `credit`, with `amount_cents` off the next bill and the date `applies_on`. It is `null` when no reward applies.
- **Entering a friend's code.** `POST /api/v1/referrals/me/referrer` is allowed once, and only before you ever had a plan. It answers `200` with the same summary as `GET /api/v1/referrals/me`. `can_add_code` says whether it may succeed.
- **Code at sign-up.** A friend can also pass `referral_code` and `referral_source` when signing in. See [Authentication](https://renzo-digital.com/docs/authentication).
- **Your own code.** It answers `409` [`referral_own_code`](https://renzo-digital.com/docs/error-codes#referral_own_code).
- **Already set.** A second code answers `409` [`referrer_already_set`](https://renzo-digital.com/docs/error-codes#referrer_already_set).
- **Had a plan.** An account that ever had a plan answers `409` [`referral_not_eligible`](https://renzo-digital.com/docs/error-codes#referral_not_eligible).
- **No code for you.** An account that cannot have a referral code answers `409` [`referral_cannot_refer`](https://renzo-digital.com/docs/error-codes#referral_cannot_refer) on `GET /api/v1/referrals/me`.
- **Discount at checkout.** The discount shows in the checkout preview. See [Billing](https://renzo-digital.com/docs/resources/billing).

## Errors

| Code | Status | When |
| --- | --- | --- |
| [`referral_code_not_found`](https://renzo-digital.com/docs/error-codes#referral_code_not_found) | 404 | No active referral code matches, or the program is off. |
| [`referral_own_code`](https://renzo-digital.com/docs/error-codes#referral_own_code) | 409 | You cannot use your own code. |
| [`referrer_already_set`](https://renzo-digital.com/docs/error-codes#referrer_already_set) | 409 | Your account already has a referrer. |
| [`referral_not_eligible`](https://renzo-digital.com/docs/error-codes#referral_not_eligible) | 409 | Only an account that never had a plan can add a code. |
| [`referral_cannot_refer`](https://renzo-digital.com/docs/error-codes#referral_cannot_refer) | 409 | The account cannot have a referral code. |
| [`profile_incomplete`](https://renzo-digital.com/docs/error-codes#profile_incomplete) | 409 | The account has no username yet. |
| [`rate_limited`](https://renzo-digital.com/docs/error-codes#rate_limited) | 429 | Too many public checks from this IP address. |

Sign-in and request errors, such as [`token_expired`](https://renzo-digital.com/docs/error-codes#token_expired) and [`validation_failed`](https://renzo-digital.com/docs/error-codes#validation_failed), can come from any call. See [Errors](https://renzo-digital.com/docs/concepts/errors).

## Reference

- [Referrals in the API reference](https://renzo-digital.com/docs/api#tag/referrals)
