import Whop from '@whop/sdk';
const client = new Whop({
apiKey: process.env['WHOP_API_KEY'], // This is the default and can be omitted
});
const affiliate = await client.affiliates.create({
company_id: 'biz_xxxxxxxxxxxxxx',
user_identifier: 'user_identifier',
});
console.log(affiliate.id);{
"id": "aff_xxxxxxxxxxxxxx",
"status": "active",
"created_at": "2023-12-01T05:00:00.401Z",
"updated_at": "2023-12-01T05:00:00.401Z",
"total_referrals_count": 42,
"total_referral_earnings_usd": "<string>",
"total_overrides_count": 42,
"customer_retention_rate": "<string>",
"customer_retention_rate_ninety_days": "<string>",
"monthly_recurring_revenue_usd": "<string>",
"total_revenue_usd": "<string>",
"active_members_count": 42,
"user": {
"id": "user_xxxxxxxxxxxxx",
"name": "Jane Smith",
"username": "janesmith"
},
"company": {
"id": "biz_xxxxxxxxxxxxxx",
"title": "<string>"
}
}Creates or finds an affiliate for a company and user.
Required permissions:
affiliate:createimport Whop from '@whop/sdk';
const client = new Whop({
apiKey: process.env['WHOP_API_KEY'], // This is the default and can be omitted
});
const affiliate = await client.affiliates.create({
company_id: 'biz_xxxxxxxxxxxxxx',
user_identifier: 'user_identifier',
});
console.log(affiliate.id);{
"id": "aff_xxxxxxxxxxxxxx",
"status": "active",
"created_at": "2023-12-01T05:00:00.401Z",
"updated_at": "2023-12-01T05:00:00.401Z",
"total_referrals_count": 42,
"total_referral_earnings_usd": "<string>",
"total_overrides_count": 42,
"customer_retention_rate": "<string>",
"customer_retention_rate_ninety_days": "<string>",
"monthly_recurring_revenue_usd": "<string>",
"total_revenue_usd": "<string>",
"active_members_count": 42,
"user": {
"id": "user_xxxxxxxxxxxxx",
"name": "Jane Smith",
"username": "janesmith"
},
"company": {
"id": "biz_xxxxxxxxxxxxxx",
"title": "<string>"
}
}A company API key, company scoped JWT, app API key, or user OAuth token. You must prepend your key/token with the word 'Bearer', which will look like Bearer ***************************
A successful response
An affiliate tracks a user's referral performance and commission earnings for a company, including retention rates, revenue metrics, and payout configurations.
The unique identifier for the affiliate.
"aff_xxxxxxxxxxxxxx"
The status of the affiliate
active, archived, deleted The datetime the affiliate was created.
"2023-12-01T05:00:00.401Z"
The datetime the affiliate was last updated.
"2023-12-01T05:00:00.401Z"
The total referrals of the affiliate
42
The total commission earnings paid to this affiliate, formatted as a USD currency string
The total count of all overrides for this affiliate
42
The percentage of referred customers who are still active members
The percentage of referred customers who remained active over the last 90 days
The monthly recurring revenue generated by this affiliate's referrals, formatted as a USD currency string
The total revenue generated from this affiliate's referrals, formatted as a USD currency string
The total active members of the affiliate
42
The user attached to this affiliate
Show child attributes
The company attached to this affiliate
Show child attributes
Was this page helpful?