Referral Codes API

Create and manage referral codes for your users.

Referral codes are unique identifiers that link a referral to a specific user. Each user can have one code per campaign.

POST/v1/links

Create a new referral link for a user. If a link already exists for this user and campaign, returns the existing link.

Parameters

NameTypeRequiredDescription
userIdstringRequiredYour unique identifier for the user
campaignIdstringRequiredThe campaign to create the link for
metadataobjectOptionalCustom metadata to attach to the link

Request Body

{
  "userId": "user_123",
  "campaignId": "camp_xxxxx",
  "metadata": {
    "source": "dashboard",
    "plan": "pro"
  }
}

Response

{
  "id": "link_xxxxx",
  "url": "https://refer.yourapp.com/abc123",
  "code": "abc123",
  "userId": "user_123",
  "campaignId": "camp_xxxxx",
  "metadata": {
    "source": "dashboard",
    "plan": "pro"
  },
  "clickCount": 0,
  "conversionCount": 0,
  "createdAt": "2024-01-15T10:30:00Z"
}
GET/v1/links/:code

Get details for a specific referral link by its code.

Parameters

NameTypeRequiredDescription
codestringRequiredThe referral code (from URL path)

Response

{
  "id": "link_xxxxx",
  "url": "https://refer.yourapp.com/abc123",
  "code": "abc123",
  "userId": "user_123",
  "campaignId": "camp_xxxxx",
  "clickCount": 42,
  "conversionCount": 5,
  "createdAt": "2024-01-15T10:30:00Z"
}
GET/v1/users/:userId/links

Get all referral links for a specific user.

Parameters

NameTypeRequiredDescription
userIdstringRequiredYour user identifier (from URL path)
campaignIdstringOptionalFilter by campaign

Response

{
  "data": [
    {
      "id": "link_xxxxx",
      "url": "https://refer.yourapp.com/abc123",
      "code": "abc123",
      "campaignId": "camp_xxxxx",
      "clickCount": 42,
      "conversionCount": 5,
      "createdAt": "2024-01-15T10:30:00Z"
    }
  ],
  "total": 1
}
Referral links are idempotent. Creating a link for the same user and campaign will return the existing link rather than creating a duplicate.