Setup
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.
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.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.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).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
Your Refairn business ID. Found in Settings → Integrations.
The ID of the specific product this customer signed up for. Found in Settings → Integrations.
The email address the customer used to register. This is the primary key used for attribution matching.
The customer’s full name as provided during signup.
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
true if the event was accepted and processed.The unique ID of the lead record created in Refairn for this customer.
The ID of the agent the customer was attributed to.
null if no attribution was found.The attribution model used. Currently always
first_touch.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
Your Refairn business ID.
The ID of the product the payment is for.
The customer’s email address. Must match the email used when the lead was created.
The payment amount as a number in the currency’s standard unit. For example,
100 for USD 29.99 charge.ISO 4217 currency code. For example,
"USD", "NGN", "GBP".The subscription state after this payment. One of:
active, trialing, past_due, cancelled.The date the payment was confirmed, in
YYYY-MM-DD format.Response
true if the event was accepted and a commission record was created or updated.The unique ID of the commission record created for this payment.
The agent who will receive the commission.
The calculated commission amount in the same currency as the payment.
The initial status of the commission. Always
pending on creation—commissions move to approved after the hold period passes with no refund or dispute.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
| Status code | Cause | What to do |
|---|---|---|
400 Bad Request | Missing or invalid fields in your payload | Check required fields; inspect the message field in the response body for specifics |
401 Unauthorized | Missing or invalid API key | Verify Authorization: Bearer YOUR_API_KEY header is present and the key is valid |
403 Forbidden | API key does not match the businessId in the payload | Confirm the key was generated for this business account |
404 Not Found | Unknown businessId or productId | Check Settings → Integrations for your correct IDs |
409 Conflict | Duplicate event already processed | Safe to ignore—Refairn has already recorded this event |
5xx Server Error | Transient server issue | Retry with exponential backoff (wait 1s, 2s, 4s between attempts) |
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.