Affiliate API Routes Documentation

The Affiliate API provides REST endpoints for managing affiliate codes and tracking affiliate statistics.

Users can create their own affiliate codes, use codes from other users, and track their earnings from referred users.

Base Path: /affiliate


Endpoints

1. GET /affiliate/stats

Get affiliate statistics for the authenticated user, including all referred users and their earnings.

Authentication

Required: Yes

Response

Returns an array of affiliate objects representing users who used the authenticated user's affiliate code.

Array<{
    username: string;
    avatar: string;
    deposited: number;
    withdraws: number;
    steamid: string;
    earned: number;
}>;

Example Request

Example Response

Notes

  • Results are sorted by earned amount (highest first)

  • earned is calculated as: (deposited - (withdraws + bonuses)) * affiliateShare

  • Affiliate share percentage varies based on the user's lifetime losses (0.08 to 0.25)

  • Returns an empty array if the user has no affiliates

Error Responses

401 Unauthorized

500 Internal Server Error

2. GET /affiliate/overview

Get aggregated affiliate statistics for the authenticated user.

Authentication

Required: Yes

Response

Returns a summary object containing total earnings, deposit stats, and commission rates.

Field
Type
Description

commissionPercentage

Number

Current commission rate (0.08 - 0.25)

totalDeposits

Number

Total amount deposited by all referrals

totalWithdraws

Number

Total amount withdrawn by all referrals

totalAffiliates

Number

Count of users who used your code

totalEarnings

Number

Lifetime earnings generated

availableEarnings

Number

Current claimable earnings


3. POST /affiliate/set-code

Set an affiliate code for the authenticated user. Once set, other users can use this code to become the user's affiliates.

Authentication

Required: Yes

Request Body

Response (Success)

Example Request

Example Response (Success)

Error Responses

400 Bad Request - Missing Code

400 Bad Request - Invalid Format

400 Bad Request - Invalid Length

400 Bad Request - Code Already Taken

400 Bad Request - User Already Has Code

400 Bad Request - No Changes

401 Unauthorized

500 Internal Server Error

Validation Rules

  • Code must be 4-24 characters long

  • Code must contain only letters and numbers (alphanumeric)

  • Code must be unique across all users

  • User can only set their code once (cannot change it later)

  • Code is automatically converted to uppercase


4. POST /affiliate/use-code

Use an affiliate code to become someone's affiliate. Grants a signup bonus and establishes the affiliate relationship.

Authentication

Required: Yes

Request Body

Response (Success)

Example Request

Example Response (Success)

Error Responses

400 Bad Request - Missing Code

400 Bad Request - Invalid Code

400 Bad Request - Own Code

400 Bad Request - Already Used

401 Unauthorized

500 Internal Server Error

Effects

When a user successfully uses an affiliate code:

  1. User receives bonus: +0.2 to balance

  2. Affiliate relationship created: User is added to code owner's affiliates list

  3. Rewards updated: User's depositBonus set to true, freeCases set to 0

  4. Permanent record: User's affiliate.used field is set (cannot use another code)


Data Models

Affiliate Statistics Object

User Affiliate Schema

Affiliate Database Schema


Affiliate Commission System

Commission Tiers

Commission percentage is based on the affiliate owner's lifetime losses:

Lifetime Loss
Commission Rate

≥ $100,000

25%

≥ $50,000

20%

≥ $10,000

12%

≥ $5,000

10%

< $5,000

8%

Earnings Calculation

Example

If an affiliate:

  • Deposited: $500

  • Withdrew: $100

  • Received bonuses: $50

  • Code owner's commission rate: 12%

Earnings = ($500 - ($100 + $50)) * 0.12 = $42


Frontend Integration

Example: Fetching Affiliate Stats

Example: Setting Affiliate Code

Example: Using Affiliate Code

Example: Complete Affiliate Dashboard


Security Considerations

Authentication

  • Cookies must be included in requests (credentials: "include")


Troubleshooting

Common Issues

Issue: 401 Unauthorized on all requests

  • Cause: Missing or invalid session cookie

  • Solution: Ensure cookies are included in requests (credentials: "include")

Issue: Code already taken error

  • Cause: Another user has already claimed this code

  • Solution: Choose a different, unique code

Issue: Cannot change affiliate code

  • Cause: Users can only set their code once

  • Solution: This is by design to prevent abuse

Issue: Affiliate stats showing empty array

  • Cause: No users have used your affiliate code yet

  • Solution: Share your code with others to gain affiliates

Issue: Cannot use affiliate code twice

  • Cause: Users can only use one affiliate code per account

  • Solution: This is by design to prevent bonus farming