All documentation
Referral Program - cred.diy API documentation
Referral Program
Create a referral program for your users to earn credits by inviting others. Configure rewards for both referrers and referees programmatically via the API.
Configure Referral Settings
Set up your referral program by configuring how many credits referrers and referees receive.
// Configure referral program settings
const response = await fetch(
'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/referral-settings',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'sk_live_your_api_key'
},
body: JSON.stringify({
is_active: true,
referrer_credits: 100,
referee_credits: 50,
credit_type_id: 'your_credit_type_id'
})
}
);
const result = await response.json();
// {
// success: true,
// settings: {
// id: '...',
// is_active: true,
// referrer_credits: 100,
// referee_credits: 50,
// credit_type_id: '...',
// credit_type_name: 'Tokens'
// }
// }Generate Referral Code
Generate a unique referral code for a user. If the user already has a code, it returns the existing one.
// Generate a referral code for a user
const response = await fetch(
'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/referrals/generate-code',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'sk_live_your_api_key'
},
body: JSON.stringify({
user_id: 'user_123'
})
}
);
const result = await response.json();
// {
// success: true,
// user_id: 'user_123',
// referral_code: 'ABC12XYZ'
// }Apply Referral Code
When a new user signs up with a referral code, apply it to award credits to both parties.
// Apply a referral code for a new user
const response = await fetch(
'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/referrals/apply',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'sk_live_your_api_key'
},
body: JSON.stringify({
user_id: 'new_user_456',
referral_code: 'ABC12XYZ'
})
}
);
const result = await response.json();
// {
// success: true,
// referral_id: '...',
// referrer_credits_issued: 100,
// referee_credits_issued: 50
// }List Referrals
Retrieve all referrals for your project with optional filtering by status.
// List all referrals for your project
const response = await fetch(
'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/referrals?status=completed&limit=50',
{
headers: {
'x-api-key': 'sk_live_your_api_key'
}
}
);
const result = await response.json();
// {
// referrals: [{ id: '...', referral_code: 'ABC12XYZ', status: 'completed', ... }],
// total: 25,
// limit: 50,
// offset: 0
// }Referral API Endpoints
| Endpoint | Description |
|---|---|
| GET /referral-settings | Get current referral program settings |
| POST /referral-settings | Create or update referral settings |
| POST /referrals/generate-code | Generate a referral code for a user |
| POST /referrals/apply | Apply a referral code (issues credits) |
| GET /referrals | List all referrals with filtering |
Integration Flow
- Configure your referral settings (credits for referrer/referee)
- Generate referral codes for existing users
- Display the code in your app for users to share
- When new users sign up, apply the referral code
- Credits are automatically issued to both parties
Your first credit is one request away.
Create a project, copy an API key, and issue a credit from your server.
