Demo docs: examples are illustrative.
Referral API

Quickstart

Track your first referral and watch a reward unlock in about ten minutes.

This guide uses test mode, so nothing you do here affects real customers or balances.

Create a program

In the dashboard, open Program builder and choose a template. Give and get is a good default: the friend gets a discount, and the referrer gets credit when the friend pays.

The program builder with a give-and-get program

Copy the program ID from the page header. It looks like prog_8Hq2LmN4.

Install the SDK

npm install @referral-api/js

Add your test secret key to your environment:

.env.local
REFERRAL_API_KEY=sk_test_51Hx...

Secret keys can create rewards. Only use them on your server, never in browser code.

Enroll a referrer

Create a referrer for one of your existing customers. The response includes their share link.

enroll.ts
import { ReferralClient } from '@referral-api/js';

const client = new ReferralClient({ apiKey: process.env.REFERRAL_API_KEY! });

const referrer = await client.referrers.create({
  programId: 'prog_8Hq2LmN4',
  externalId: 'user_1042', 
  email: 'maya@example.com',
});

console.log(referrer.shareUrl); // https://acme.example/?ref=MAYA-20

Track the signup and payment

When the friend creates an account, send the signup with the referral code. When they pay, send the payment.

events.ts
await client.events.signup({
  externalId: 'user_2088',
  email: 'sam@example.com',
  referralCode: 'MAYA-20',
});

await client.events.payment({
  externalId: 'user_2088',
  paymentId: 'in_1PqR2s',
  amount: 4900, // in cents
  currency: 'usd',
});

Fast-forward the hold period

Rewards wait for the refund window before they unlock. In test mode you can skip ahead:

await client.testClock.advance({ days: 30 });

Open Rewards in the dashboard. Maya's $20 credit is now unlocked and ready to pay.

Next steps

How is this guide?