Setup
1
Generate your API key
In your Refairn business dashboard, go to Settings → Integrations. Click Generate API Key. Copy the key immediately—it is only shown once. If you lose it, revoke it and generate a new one.
2
Store the key securely
Add the key to your server-side environment variables. Reference it as
REFAIRN_API_KEY in your code. Never hard-code the value directly in source files.3
Locate your business and product IDs
Your
businessId and productId are shown in Settings → Integrations alongside your API key. You will include these in every event payload you send.4
Instrument your signup flow
After a new user successfully creates an account in your SaaS, call the
customer-created endpoint. Pass the customer’s email, name, and the referral code from the cookie set by Refairn’s tracking link (if present).5
Instrument your payment flow
After a payment is confirmed in your billing system, call the
payment-succeeded endpoint. Pass the customer’s email, the payment amount, currency, and date.Authentication
All API requests must include your API key in theAuthorization header as a Bearer token.
401 Unauthorized. Requests with a key that does not match the businessId in the payload return 403 Forbidden.
Customer created event
Send this event from your signup handler immediately after a new user account is created in your SaaS. Refairn records the customer, looks up the referring agent from thereferralCode (or from the tracking cookie if the code was set during the referral link click), and creates a lead record attributed to that agent.
Request
POST /api/events/customer-created
string
required
Your Refairn business ID. Found in Settings → Integrations.
string
required
The ID of the specific product this customer signed up for. Found in Settings → Integrations.
string
required
The email address the customer used to register. This is the primary key used for attribution matching.
string
required
The customer’s full name as provided during signup.
string
The agent’s referral code. Read this from the tracking cookie set when the customer clicked a Refairn referral link (
refairn_code). Omit this field if the customer did not arrive via a referral link.Response
boolean
true if the event was accepted and processed.string
The unique ID of the lead record created in Refairn for this customer.
string
The ID of the agent the customer was attributed to.
null if no attribution was found.string
The attribution model used. Currently always
first_touch.string
A human-readable confirmation message.
Code examples
Payment succeeded event
Send this event from your billing or payment confirmation handler every time a customer completes a payment—initial subscriptions, monthly renewals, annual renewals, and one-time charges all qualify. Refairn looks up the agent attribution for the customer’s email and queues the appropriate commission.Request
POST /api/events/payment-succeeded
string
required
Your Refairn business ID.
string
required
The ID of the product the payment is for.
string
required
The customer’s email address. Must match the email used when the lead was created.
number
required
The payment amount as a number in the currency’s standard unit. For example,
100 for USD 29.99 charge.string
required
ISO 4217 currency code. For example,
"USD", "NGN", "GBP".string
required
The subscription state after this payment. One of:
active, trialing, past_due, cancelled.string
required
The date the payment was confirmed, in
YYYY-MM-DD format.Response
boolean
true if the event was accepted and a commission record was created or updated.string
The unique ID of the commission record created for this payment.
string
The agent who will receive the commission.
number
The calculated commission amount in the same currency as the payment.
string
The initial status of the commission. Always
pending on creation—commissions move to approved after the hold period passes with no refund or dispute.string
The date after which the commission is eligible for approval, in
YYYY-MM-DD format. Based on your program’s hold period setting.Code examples
Error handling
Refairn events are idempotent for the same
customerEmail + paymentDate combination on payment events, and the same customerEmail on customer-created events. Retrying a successfully processed event returns a 409 and will not create duplicates.
Testing
Use your live API key against the production endpoint during development—Refairn does not currently offer a separate sandbox environment. To avoid creating real commission records during testing, use a dedicated test product created in your dashboard with a$0.00 commission rate. Delete test customer and commission records from the Customers section of the dashboard after each test run.