Skip to main content
DocsAPI ReferenceReferral API
Back to docs

Referral API

Referral links, conversions, stats

api
referral

Referral API

Base path: /api/referral

Manages the referral program: link generation, conversion tracking, and reward statistics. Referrers earn 5 extra AI generation credits per successful conversion.


Get the authenticated user's unique referral link. If the user does not yet have a referral code, one is generated automatically (8-character uppercase hex string).

Auth: Required (JWT) Feature gate: None

Response:

{
  "success": true,
  "data": {
    "code": "A1B2C3D4",
    "link": "https://app.creatiq.com/login?ref=A1B2C3D4"
  }
}
FieldTypeDescription
codestring8-character uppercase referral code
linkstringFull referral URL pointing to the login page with ref query parameter

Errors:

StatusBodyCondition
500{ "success": false, "error": "Failed to get referral link" }User not found or database error

POST /api/referral/convert

Process a referral code during a new user's registration. This endpoint:

  1. Looks up the referrer by referralCode.
  2. Records the conversion in the referrals table.
  3. Links the new user to the referrer (referred_by column).
  4. Awards the referrer 5 bonus AI generation credits.

All steps run inside a database transaction.

Auth: None (public -- called during registration) Feature gate: None

Request body:

{
  "referralCode": "A1B2C3D4",
  "email": "newuser@example.com"
}
FieldTypeRequiredConstraints
referralCodestringYesMin 1, max 20 characters
emailstringYesValid email, max 255 characters

Response (success):

{
  "success": true,
  "data": {
    "converted": true,
    "referrerId": "referrer-uuid"
  }
}

Response (invalid code):

{
  "success": true,
  "data": {
    "converted": false,
    "referrerId": null
  }
}
FieldTypeDescription
convertedbooleanWhether the referral was successfully processed
referrerIdstring | nullUUID of the referrer, or null if the code was invalid

Errors:

StatusBodyCondition
400{ "success": false, "error": "Validation error: ..." }Zod validation failure
500{ "success": false, "error": "Failed to convert referral" }Database or transaction error

GET /api/referral/stats

Get referral statistics for the authenticated user.

Auth: Required (JWT) Feature gate: None

Response:

{
  "success": true,
  "data": {
    "totalReferrals": 10,
    "convertedReferrals": 6,
    "pendingReferrals": 4,
    "totalRewards": 30
  }
}
FieldTypeDescription
totalReferralsnumberTotal referral records for this user
convertedReferralsnumberReferrals with status converted
pendingReferralsnumberReferrals with status pending
totalRewardsnumberTotal bonus credits earned (convertedReferrals x 5)

Errors:

StatusBodyCondition
500{ "success": false, "error": "Failed to get referral stats" }Database error
Back to docsdocs/product/api/referral.md