---
title: "Invite Rewards"
icon : "users"
description: "Attribute a join to an inviter, and the public endpoints behind the invite page."
---

# Invite Rewards

One endpoint here takes an API token: **attribution**, which reports who invited a new member. The rest are the public endpoints behind `/invite/<slug>` — they authenticate the visitor with a Discord cookie, not a Bearer token.

<Warning title="Config endpoints are dashboard-only">
  `/api/v3/projects/:project_uuid/invites/config` and `/overview` are gated by the dashboard session cookie plus CSRF and are **not** reachable with an API token. Configure the program under **Rewards → Invite Rewards**.
</Warning>

## Attribute a join

<Endpoint
  method="POST"
  path  ="https://api.envyauth.my.id/api/v3/projects/:project_uuid/invites/attribute"
/>

Records that a freshly-joined member came in through a specific invite code. This is what the Discord bot calls after resolving its join diff.

```bash
curl -X POST https://api.envyauth.my.id/api/v3/projects/<project_uuid>/invites/attribute \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"invitee_discord_id":"1118453649727823974","invite_code":"7hncts"}'
```

| Field | Type | Required | Meaning |
|---|---|---|---|
| `invitee_discord_id` | string | yes | 17–20 digit Discord snowflake of the member who joined. |
| `invite_code` | string | yes | The invite code they used, 1–32 characters. |

The inviter is **not** a parameter. It's resolved server-side from the invite code, so a caller can never credit an arbitrary account.

```json
{
  "success": true,
  "data": { "attributed": true },
  "requestid": "uuid"
}
```

A join that doesn't qualify is still a `200` with `attributed: false` and a reason, so the bot never retries a legitimately-skipped join.

| Reason | Meaning |
|---|---|
| `disabled` | The project has no active invite program. |
| `untracked_invite` | The code isn't a tracked personal invite for this project. |
| `self_invite` | The invitee and the inviter are the same account. |
| `account_too_new` | The invitee's Discord account is younger than the configured minimum. |
| `already_member` | The invitee already holds a key in this project. |

When the program's qualify mode is `join`, a successful attribution pays out immediately. `redeem` and `redeem_exec` leave it pending until their own trigger fires.

| Status | Code | Meaning |
|---|---|---|
| 404 | `NOT_FOUND` | The project doesn't belong to this token's account. |
| 400 | `BAD_REQUEST` | Missing JSON content type or unparseable body. |
| 422 | `VALIDATION` | Bad snowflake or invite code. |

## Public endpoints

The endpoints below back the public `/invite/<slug>` page. They take a `token` query parameter — the program's `slug_token` — and identify the visitor from their Discord cookie. All are rate-limited per IP, and the write endpoints are additionally throttled per Discord identity.

A missing or disabled program returns `404` with `code: "NOT_FOUND"` on every one of them.

### Program info

<Endpoint
  method="GET"
  path  ="https://api.envyauth.my.id/api/v3/invites/s/:slug_token"
/>

The public, non-secret slice of the config: rules text, reward terms, caps, and the economy settings. It never exposes the project UUID or owner internals.

```json
{
  "success": true,
  "data": {
    "config": {
      "slug":            "atomic-hub",
      "enabled":         true,
      "project_name":    "Atomic Hub",
      "qualify_mode":    "redeem",
      "reward_type":     "points",
      "reward_amount":   3,
      "per_inviter_cap": 30,
      "min_invitee_account_age_days": 7,
      "milestones":      [{ "count": 5, "bonus": 10 }],
      "rules_text":      "One invite counts once the friend redeems a key.",
      "reward_currency": "points",
      "rate_per_invite": 1,
      "points_per_unit": 1,
      "budget_exhausted": false
    }
  },
  "requestid": "uuid"
}
```

`budget_exhausted` means the owner's budget cap is spent and new earns are paused until they top it up.

### Visitor progress

<Endpoint
  method="GET"
  path  ="https://api.envyauth.my.id/api/v3/invites/me?token=:slug_token"
/>

The signed-in visitor's identity, progress, wallet, and existing invite link.

Without a visitor cookie this still returns `200`, with `authed: false` and the config only, so the page can render its sign-in state.

```json
{
  "success": true,
  "data": {
    "authed":  true,
    "visitor": { "discord_id": "…", "username": "someone", "avatar": "…" },
    "config":  { },
    "progress": {
      "qualified":     21,
      "pending":       3,
      "reward_earned": 147,
      "reward_unit":   "points",
      "cap":           30
    },
    "wallet": {
      "balance":         42,
      "lifetime_earned": 147,
      "currency":        "points",
      "matured":         42
    },
    "invite":   { "code": "7hncts", "url": "https://discord.gg/7hncts" },
    "page_url": "https://envyauth.my.id/invite/atomic-hub"
  },
  "requestid": "uuid"
}
```

`wallet` is `null` for programs that don't use points or cash. For a cash program, `matured` is the portion that has cleared the maturation hold and can actually be withdrawn.

### Create or fetch the invite link

<Endpoint
  method="POST"
  path  ="https://api.envyauth.my.id/api/v3/invites/link?token=:slug_token"
/>

Returns the visitor's personal Discord invite, creating it on first call and reusing it afterwards so the link stays stable.

```json
{
  "success": true,
  "data": { "code": "7hncts", "url": "https://discord.gg/7hncts" },
  "requestid": "uuid"
}
```

| Status | Code | Meaning |
|---|---|---|
| 401 | `UNAUTHORIZED` | No Discord visitor cookie. |
| 409 | `NOT_CONFIGURED` | No guild linked, or no channel to mint the invite against. |
| 502 | `INVITE_FAILED` | Discord refused — the bot is missing **Create Invite** on the server. |

### Redeem points

<Endpoint
  method="POST"
  path  ="https://api.envyauth.my.id/api/v3/invites/wallet/redeem?token=:slug_token"
/>

Spends points from the visitor's wallet into the owner-configured reward. Only valid when the program's reward type is `points`.

```bash
curl -X POST "https://api.envyauth.my.id/api/v3/invites/wallet/redeem?token=<slug_token>" \
  -H "Content-Type: application/json" \
  -d '{"units":3}'
```

| Field | Type | Required | Meaning |
|---|---|---|---|
| `units` | integer | yes | How many units of the redeem reward to buy, 1–100,000. Cost is `units × points_per_unit`. |

```json
{
  "success": true,
  "data": {
    "redeem_type":  "whitelist_days",
    "units":        3,
    "spent":        3,
    "balance":      39,
    "applied_days": 3
  },
  "requestid": "uuid"
}
```

The balance decrement and the reward application happen in one atomic step. A Discord-role redemption is assigned by the bot right after the balance clears.

| Status | Code | Meaning |
|---|---|---|
| 401 | `UNAUTHORIZED` | No Discord visitor cookie. |
| 409 | `NOT_REDEEMABLE` | This program doesn't use redeemable points. |
| 409 | `INSUFFICIENT` | Not enough points for that redemption. |

### Request a cash payout

<Endpoint
  method="POST"
  path  ="https://api.envyauth.my.id/api/v3/invites/payout/request?token=:slug_token"
/>

Reserves a payout from the visitor's matured balance. Only valid on a `cash` program with payouts enabled.

```bash
curl -X POST "https://api.envyauth.my.id/api/v3/invites/payout/request?token=<slug_token>" \
  -H "Content-Type: application/json" \
  -d '{"amount":50000}'
```

| Field | Type | Required | Meaning |
|---|---|---|---|
| `amount` | integer | yes | Amount in minor units, 1–1,000,000,000. |

```json
{
  "success": true,
  "data": { "payout_id": "uuid", "amount": 50000, "balance": 12000 },
  "requestid": "uuid"
}
```

| Status | Code | Meaning |
|---|---|---|
| 401 | `UNAUTHORIZED` | No Discord visitor cookie. |
| 409 | `PAYOUT_DISABLED` | Not a cash program, or payouts are switched off. |
| 409 | `NOT_MATURED` | That amount hasn't cleared the maturation hold yet. |
| 409 | `BELOW_THRESHOLD` | Below the program's minimum payout. |

### Leaderboard

<Endpoint
  method="GET"
  path  ="https://api.envyauth.my.id/api/v3/invites/leaderboard?token=:slug_token"
/>

Top 10 inviters by qualified-invite count. No auth needed, but the caller's own row is marked when a visitor cookie is present.

```json
{
  "success": true,
  "data": {
    "currency":    "points",
    "reward_type": "points",
    "entries": [
      {
        "rank":            1,
        "username":        "someone",
        "avatar_url":      "…",
        "qualified_count": 21,
        "lifetime_earned": 147,
        "is_you":          false
      }
    ]
  },
  "requestid": "uuid"
}
```

Ranking uses `lifetime_earned`, which never decreases, so spending points or cashing out doesn't cost anyone their position. Usernames resolve from the project's whitelist rows; an unresolved inviter falls back to a shortened id.
