Connecting RolePlay Ray to the referral and partner programs
The RolePlay Ray site and the RolePlay Ray CRM stay the source of truth. They tell this program a few things: a client's first payment cleared, a client's roster was loaded, a client canceled, and who referred a company. This program enrolls every client leader and rep, moves each referral from received to signed to earned, emails the referrer at every step, and sends a signed webhook back so the CRM can tag the contact. It counts the holding period itself; nothing has to report it.
1. The customer endpoint (first payment, roster, rep switch, cancel)
POST https://partners.roleplayray.com/api/roleplayray/customer
Signed with the shared secret ROLEPLAYRAY_SITE_SECRET, the same value on the RolePlay Ray site and here. Header X-RolePlayRay-Signature: t=<unix seconds>,v1=<hex>, where the hex is HMAC-SHA256 of <t>.<raw body>. A signature older than five minutes is refused.
customer.paid: the client's first payment cleared. Enrolls the payer (a sales leader or owner) in the Referral Program and, if someone referred the company, moves that referral to Signed. Sendmonthly_fee_centsso a Preferred Partner's share can be worked out.roster.loaded: the client's rep roster was loaded. Enrolls each rep, unless that company has switched rep participation off. Safe to send again when the roster changes; nobody is enrolled twice.company.updated: the client changed its answer to "May your reps take part in the referral program?" Sendreps_can_participate.customer.canceled: the client canceled. A referral that has not been paid moves to Canceled, so no reward is owed, and a Preferred Partner's unpaid shares for that client are voided.
Use the same customer.id every time for the same client company, and the same id the site sent asexternal_id on referral.created. The CRM contact id is the safest choice. event_id makes every call safe to retry. Name display on the leaderboard is never sent here: only the person can choose it, in their own portal.
| Field | Type | Required | Notes |
|---|---|---|---|
| event | "customer.paid" | "roster.loaded" | "company.updated" | "customer.canceled" | yes | |
| event_id | string | yes | Unique per event, for example the Stripe event id. A retry with the same id changes nothing. |
| occurred_at | string (date-time) | yes | |
| customer | object | yes | |
| referral_code | object | no | customer.paid: the referrer's code, from the ref parameter, from Ray's demo call, or from the Who referred you field. |
| referral_source | "link" | "demo_call" | "partner_line" | "signup" | no | customer.paid: where the code was captured. |
| amount_cents | integer | no | customer.paid: the first charge in cents. |
| monthly_fee_cents | integer | no | customer.paid: the client's monthly platform fee in cents. A Preferred Partner's share is a percent of this. |
| reps_can_participate | boolean | no | The client's answer to 'May your reps take part in the referral program?'. Omit to leave it as it is; a new company starts at yes. |
| reps | array | no | roster.loaded: the client's sales reps. |
| owner_email | string (email) | no | The RolePlay Ray team member who owns the account. Defaults to PROGRAM_DEFAULT_REP_EMAIL. |
| enroll | boolean | no | customer.paid: enroll the payer in the Referral Program. Default true. |
| welcome_delay_days | integer | no | Hold the welcome email this many days. Default 0. |
| Field | Type | Required | Notes |
|---|---|---|---|
| customer.id | string | yes | The id RolePlay Ray uses for this client company everywhere. Use the same id the site sent as external_id on referral.created; the CRM contact id is recommended. |
| customer.company | string | no | The client company's name. Required the first time a company is seen. |
| customer.email | string (email) | no | customer.paid: the payer's email. |
| customer.first_name | string | no | |
| customer.last_name | string | no | |
| customer.phone | string | no |
{
"event": "customer.paid",
"event_id": "evt_1QxYz2AbCdEf",
"occurred_at": "2026-12-01T16:20:00Z",
"customer": {
"id": "cus_Q9m3Fz7T",
"company": "Smith Home Exteriors",
"email": "jane@smithhome.example",
"first_name": "Jane",
"last_name": "Smith",
"phone": "+17205550142"
},
"referral_code": "K7Q2M9AB",
"referral_source": "demo_call",
"amount_cents": 59600,
"monthly_fee_cents": 59600,
"reps_can_participate": true,
"owner_email": "dave@roleplayray.com"
}A roster:
{
"event": "roster.loaded",
"event_id": "roster_cus_Q9m3Fz7T_1",
"occurred_at": "2026-12-03T18:00:00Z",
"customer": {
"id": "cus_Q9m3Fz7T",
"company": "Smith Home Exteriors"
},
"reps": [
{
"first_name": "Jordan",
"last_name": "Carter",
"email": "jordan@smithhome.example",
"phone": "+17205550150"
},
{
"first_name": "Riley",
"last_name": "Nguyen",
"email": "riley@smithhome.example"
}
]
}Answer (200):
{
"ok": true,
"partner": { "id": "<uuid>", "email": "jane@smithhome.example", "partner_code": "Z4R8T2QW", "referral_link": "https://partners.roleplayray.com/r/Z4R8T2QW", "join_link": "https://partners.roleplayray.com/join/Z4R8T2QW", "created": true },
"reps": null,
"company": { "id": "<uuid>", "reps_can_participate": true },
"queued_events": [
{ "event_type": "referral.created", "event_id": "<uuid>", "status": "accepted" },
{ "event_type": "sale.resulted", "event_id": "<uuid>", "status": "accepted" }
]
}400 names the first bad field, 401 means the signature is missing, wrong, or stale, 422 means no team member is set up yet. Retry a 500 with the same body after a minute.
// Node, on the RolePlay Ray site
import { createHmac } from "node:crypto";
const body = JSON.stringify(payload);
const t = Math.floor(Date.now() / 1000);
const v1 = createHmac("sha256", process.env.ROLEPLAYRAY_SITE_SECRET).update(`${t}.${body}`).digest("hex");
await fetch("https://partners.roleplayray.com/api/roleplayray/customer", {
method: "POST",
headers: { "Content-Type": "application/json", "X-RolePlayRay-Signature": `t=${t},v1=${v1}` },
body,
});2. The events API (a referral by code, and corrections)
Ray sells over the phone, so a referral code reaches this program three ways, and each one is areferral.created event with a different source:
link: a referrer's link opened the main site with?ref=CODE. The site remembers the code and reports it when the visitor identifies themselves.demo_call: near the end of the demo call Ray asks, "Did someone tell you about me? Do you have their code?" The caller says it and the call's workflow reports it.signup: the Who referred you field at sign-up, in case the first two were missed. (Sending the code oncustomer.paiddoes this for you.)partner_line: a call came in on a Preferred Partner's own demo number. Sendpartner_phoneinstead of a code and the call is credited to that partner.
The first referrer on record for a company keeps the credit. A code that was replaced, a link that was switched off, and a rep whose company turned rep participation off are refused, and the event appears under Failed events on the dashboard.
Checking a code before you report it
GET https://partners.roleplayray.com/api/v1/codes/K7Q2M9AB
The same bearer key. Ray's demo line can call this while the caller is still on the phone, to confirm a code it just heard. Answer: { "valid": true, "code": "K7Q2M9AB", "referrer": "Closer 4821", "program": "referral" }. Thereferrer value is the person's public name only (a first initial and last name if they agreed, a made-up name if not), so it is safe for Ray to say aloud. An unknown or inactive code answers { "valid": false, "reason": "unknown" } with status 200. Letter case and spaces do not matter.
POST https://partners.roleplayray.com/api/v1/events
Headers: Authorization: Bearer rpr_... (from the dashboard API keys page) and Content-Type: application/json. Every event carries anexternal_event_id that is stored once: 202 means stored, 200 means already stored. Machine-readable contract: /api/v1/openapi.json.
Envelope, the same for every event
| Field | Type | Required | Notes |
|---|---|---|---|
| event_type | "contact.created" | yes | |
| external_event_id | string | yes | Unique per event in your system. Retries with the same id are stored once. |
| occurred_at | string (date-time) | yes | When it happened, ISO 8601 with timezone. |
| rep_email | string (email) | yes | The RolePlay Ray team member who owns the deal, for example dave@roleplayray.com. Must match a team member on the dashboard. |
contact.created
A company record exists in RolePlay Ray's system. No referral is attached; accepted and logged only.
| Field | Type | Required | Notes |
|---|---|---|---|
| data.external_id | string | yes | RolePlay Ray's id for this company (the CRM contact id or the Stripe customer id). Use the same id on every event about it. |
| data.first_name | string | yes | |
| data.last_name | string | yes | |
| data.company | string | no | The referred company's name. |
| data.email | string (email) | no | |
| data.phone | string | no | E.164, for example +15125550142. |
| data.address1 | string | no | |
| data.city | string | no | |
| data.state | string | no | |
| data.postal_code | string | no |
curl -X POST https://partners.roleplayray.com/api/v1/events \
-H "Authorization: Bearer rpr_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"event_type": "contact.created",
"external_event_id": "evt-20260904-000120",
"occurred_at": "2026-09-04T14:30:00Z",
"rep_email": "dave@roleplayray.com",
"data": {
"external_id": "cus_R2x7Lk0Q",
"first_name": "Alex",
"last_name": "Rivera",
"company": "Rivera Windows and Doors",
"email": "alex@example.com",
"phone": "+17205550100"
}
}'referral.created
A company was referred. Send it when a visitor arrives with a ref code, when a caller gives Ray a code on the demo call, when a call comes in on a Preferred Partner's demo number, or when the Who referred you field is filled at sign-up. The first referrer on record keeps the credit.
| Field | Type | Required | Notes |
|---|---|---|---|
| data.external_id | string | yes | RolePlay Ray's id for this company (the CRM contact id or the Stripe customer id). Use the same id on every event about it. |
| data.first_name | string | yes | |
| data.last_name | string | yes | |
| data.company | string | no | The referred company's name. |
| data.email | string (email) | no | |
| data.phone | string | no | E.164, for example +15125550142. |
| data.address1 | string | no | |
| data.city | string | no | |
| data.state | string | no | |
| data.postal_code | string | no | |
| data.partner_code | string | no | The referrer's code. A referral link forwards to roleplayray.com with the code as the ref query parameter, and Ray asks for it on the demo call; report it here so the referrer is credited. Case does not matter. |
| data.partner_email | string (email) | no | The referrer's email, when the code is unknown. |
| data.partner_phone | string | no | E.164. The Preferred Partner demo number the caller dialed. Every call to that number is credited to its partner, with no code to remember. |
| data.source | "link" | "demo_call" | "partner_line" | "signup" | "portal" | "team" | "api" | no | Where the code was captured: link, demo_call (Ray asked), partner_line (a partner's own demo number), signup (the Who referred you field), or api. |
curl -X POST https://partners.roleplayray.com/api/v1/events \
-H "Authorization: Bearer rpr_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"event_type": "referral.created",
"external_event_id": "evt-20260904-000123",
"occurred_at": "2026-09-04T15:04:05Z",
"rep_email": "dave@roleplayray.com",
"data": {
"external_id": "cus_Q9m3Fz7T",
"first_name": "Jane",
"last_name": "Smith",
"company": "Smith Home Exteriors",
"email": "jane@example.com",
"phone": "+17205550142",
"partner_code": "K7Q2M9AB",
"source": "demo_call"
}
}'sale.resulted
The referred company's first payment cleared. The referral moves to Signed and the holding period starts.
| Field | Type | Required | Notes |
|---|---|---|---|
| data.external_id | string | yes | |
| data.sale_amount_cents | integer | yes | The first charge, in whole cents. 59600 is $596.00. |
| data.monthly_fee_cents | integer | no | The client's monthly platform fee, in whole cents. A Preferred Partner's share is a percent of this. |
| data.sale_date | string (date) | yes | |
| data.sale_type | "new" | "upgrade" | "referral" | no | Optional. Defaults to referral. |
curl -X POST https://partners.roleplayray.com/api/v1/events \
-H "Authorization: Bearer rpr_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"event_type": "sale.resulted",
"external_event_id": "evt-20260910-000301",
"occurred_at": "2026-09-10T20:15:00Z",
"rep_email": "dave@roleplayray.com",
"data": {
"external_id": "cus_Q9m3Fz7T",
"sale_amount_cents": 59600,
"monthly_fee_cents": 59600,
"sale_date": "2026-09-10",
"sale_type": "referral"
}
}'sale.canceled
The referred company canceled before the reward was paid. The referral moves to Canceled and no reward is owed.
| Field | Type | Required | Notes |
|---|---|---|---|
| data.external_id | string | yes | |
| data.canceled_date | string (date) | yes |
curl -X POST https://partners.roleplayray.com/api/v1/events \
-H "Authorization: Bearer rpr_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"event_type": "sale.canceled",
"external_event_id": "evt-20260912-000340",
"occurred_at": "2026-09-12T16:00:00Z",
"rep_email": "dave@roleplayray.com",
"data": {
"external_id": "cus_Q9m3Fz7T",
"canceled_date": "2026-09-12"
}
}'appointment.scheduled
A meeting was booked. Logged on the referral; the status does not change.
| Field | Type | Required | Notes |
|---|---|---|---|
| data.external_id | string | yes | |
| data.appointment_type | "demo" | "onboarding" | "other" | yes | |
| data.scheduled_for | string (date-time) | yes |
curl -X POST https://partners.roleplayray.com/api/v1/events \
-H "Authorization: Bearer rpr_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"event_type": "appointment.scheduled",
"external_event_id": "evt-20260905-000150",
"occurred_at": "2026-09-05T13:00:00Z",
"rep_email": "dave@roleplayray.com",
"data": {
"external_id": "cus_Q9m3Fz7T",
"appointment_type": "onboarding",
"scheduled_for": "2026-09-09T10:00:00-06:00"
}
}'install.scheduled
An onboarding date was set. Logged on the referral; the status does not change.
| Field | Type | Required | Notes |
|---|---|---|---|
| data.external_id | string | yes | |
| data.install_date | string (date) | yes |
curl -X POST https://partners.roleplayray.com/api/v1/events \
-H "Authorization: Bearer rpr_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"event_type": "install.scheduled",
"external_event_id": "evt-20260915-000410",
"occurred_at": "2026-09-15T18:00:00Z",
"rep_email": "dave@roleplayray.com",
"data": {
"external_id": "cus_Q9m3Fz7T",
"install_date": "2026-10-02"
}
}'install.completed
The referred company stayed a paying client through the holding period. The referral moves to Earned. The program sends this by itself every day; send it only to correct a record.
| Field | Type | Required | Notes |
|---|---|---|---|
| data.external_id | string | yes | |
| data.completed_date | string (date) | yes |
curl -X POST https://partners.roleplayray.com/api/v1/events \
-H "Authorization: Bearer rpr_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"event_type": "install.completed",
"external_event_id": "evt-20261109-000512",
"occurred_at": "2026-11-09T21:30:00Z",
"rep_email": "dave@roleplayray.com",
"data": {
"external_id": "cus_Q9m3Fz7T",
"completed_date": "2026-11-09"
}
}'referral.paid
RolePlay Ray paid the referrer's reward for this company. The referral moves to Paid. Refused when the referrer has no W-9 on file.
| Field | Type | Required | Notes |
|---|---|---|---|
| data.external_id | string | yes | |
| data.paid_date | string (date) | yes | |
| data.amount_cents | integer | no |
curl -X POST https://partners.roleplayray.com/api/v1/events \
-H "Authorization: Bearer rpr_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"event_type": "referral.paid",
"external_event_id": "evt-20261115-000600",
"occurred_at": "2026-11-15T15:00:00Z",
"rep_email": "dave@roleplayray.com",
"data": {
"external_id": "cus_Q9m3Fz7T",
"paid_date": "2026-11-15",
"amount_cents": 25000
}
}'3. Webhooks to the RolePlay Ray CRM
Add the CRM's address on the dashboard Webhooks page and pick events. Each delivery is a POST within a minute:
partner.enrolled: someone was enrolled (a leader at first payment, a rep from a roster, an approved Preferred Partner, or by hand), with their code, referral link, and join link.partner.joined: the person set up their sign-in.partner.message: a program email is due (welcome, nudge_1, nudge_2, received, signed, earned, paid, w9_request, leaderboard), withsent_bysaying whether this app sends it or the CRM should.partner.unsubscribed: the person clicked unsubscribe.referral.created: a new referral came in.referral.status_changed: every status move, withreferral_status(Received, Signed, Earned, Paid, Canceled) andprevious_referral_status.referral.manual_move: a team member marked a referral signed by hand on the dashboard.referral.paidandpayout.created: a reward was marked paid. Both carry the same fields; subscribe to whichever name reads better.w9.requested: the person's first referral signed and the one-time W-9 request was sent.w9.received: a team member marked the person's W-9 received.
Flat fields for the CRM
Every body starts with flat, top-level fields that a no-code tool can map directly, so a workflow never has to reach into a nested object. The nested partner, referral, and payout objects are still included, unchanged, for receivers that already read them.
| Field | On | Meaning |
|---|---|---|
| event | every event | The event name, the same as event_type. |
| occurred_at | every event | When it happened, ISO 8601 in UTC. |
| partner_email | every event | The partner's email. Use it to find or create the CRM contact. |
| partner_first_name | every event | First name. |
| partner_last_name | every event | Last name. |
| partner_company | every event | Company name, or null. |
| partner_phone | every event | Phone in +1 format, or null. |
| partner_code | every event | The partner's code, as in their link. |
| partner_kind | every event | customer (a Referral Program member: a client's leader or rep) or preferred (a Preferred Partner). |
| partner_tier | every event | rookie, bronze, silver, gold, or platinum, by all-time paid referrals. |
| partner_paid_count | every event | All-time paid referrals. |
| partner_status | every event | invited (no sign-in yet), active, or unsubscribed. |
| partner_w9_status | every event | not_requested, requested, or received. |
| referral_link | every event | The partner's personal referral link. |
| portal_link | every event | The partner portal address. |
| owner_email | every event | The RolePlay Ray team member who owns the partner (or, on referral events, the referral). |
| referral_status | referral and payout events | Received, Signed, Earned, Paid, or Canceled. |
| previous_referral_status | referral.status_changed, referral.manual_move | The status before the move, in the same words. |
| referred_company | referral and payout events | The referred company's name, or null. |
| referred_name | referral and payout events | The referred person as the referrer knows them, "Jane S." |
| reward_cents | referral and payout events | The reward in cents: the amount paid once paid, the expected amount before that, null when canceled. |
| reward_dollars | referral and payout events | The same amount formatted, "$250.00". |
POST <your webhook url> X-RolePlayRay-Webhook-Timestamp: 1788000000 X-RolePlayRay-Webhook-Signature: sha256=<hex HMAC-SHA256 over "<timestamp>.<raw body>" using the webhook secret> Content-Type: application/json
referral.status_changed
{
"id": "<delivery uuid>",
"event": "referral.status_changed",
"occurred_at": "2026-10-12T16:21:00Z",
"partner_id": "6f1d2c3b-4a59-4e8f-9b7a-0c1d2e3f4a5b",
"partner_email": "mike@example.com",
"partner_first_name": "Mike",
"partner_last_name": "Torres",
"partner_company": "Torres Exteriors",
"partner_phone": "+17205550188",
"partner_code": "K7Q2M9AB",
"partner_kind": "customer",
"partner_tier": "rookie",
"partner_paid_count": 0,
"partner_status": "active",
"partner_w9_status": "not_requested",
"referral_link": "https://partners.roleplayray.com/r/K7Q2M9AB",
"portal_link": "https://partners.roleplayray.com/portal",
"owner_email": "dave@roleplayray.com",
"referral_id": "0b8e7d6c-5a4f-4c3b-8a29-1f0e9d8c7b6a",
"referral_external_id": "cus_Q9m3Fz7T",
"referral_status": "Signed",
"referred_company": "Smith Home Exteriors",
"referred_name": "Jane S.",
"reward_cents": 25000,
"reward_dollars": "$250.00",
"previous_referral_status": "Received",
"event_type": "referral.status_changed",
"office_slug": "roleplayray",
"referral": {
"id": "0b8e7d6c-5a4f-4c3b-8a29-1f0e9d8c7b6a",
"external_id": "cus_Q9m3Fz7T",
"status": "sold",
"previous_status": "received",
"status_label": "Signed",
"partner_code": "K7Q2M9AB",
"partner_email": "mike@example.com",
"rep_email": "dave@roleplayray.com"
}
}payout.created
{
"id": "<delivery uuid>",
"event": "payout.created",
"occurred_at": "2026-12-14T17:05:00Z",
"partner_id": "6f1d2c3b-4a59-4e8f-9b7a-0c1d2e3f4a5b",
"partner_email": "mike@example.com",
"partner_first_name": "Mike",
"partner_last_name": "Torres",
"partner_company": "Torres Exteriors",
"partner_phone": "+17205550188",
"partner_code": "K7Q2M9AB",
"partner_kind": "customer",
"partner_tier": "bronze",
"partner_paid_count": 1,
"partner_status": "active",
"partner_w9_status": "received",
"referral_link": "https://partners.roleplayray.com/r/K7Q2M9AB",
"portal_link": "https://partners.roleplayray.com/portal",
"owner_email": "dave@roleplayray.com",
"referral_id": "0b8e7d6c-5a4f-4c3b-8a29-1f0e9d8c7b6a",
"referral_external_id": "cus_Q9m3Fz7T",
"referral_status": "Paid",
"referred_company": "Smith Home Exteriors",
"referred_name": "Jane S.",
"reward_cents": 25000,
"reward_dollars": "$250.00",
"payout_sequence_number": 1,
"event_type": "payout.created",
"office_slug": "roleplayray",
"referral": {
"id": "0b8e7d6c-5a4f-4c3b-8a29-1f0e9d8c7b6a",
"external_id": "cus_Q9m3Fz7T",
"status": "paid",
"previous_status": "installed",
"status_label": "Paid",
"partner_code": "K7Q2M9AB",
"partner_email": "mike@example.com",
"rep_email": "dave@roleplayray.com"
},
"payout": {
"amount_cents": 25000,
"sequence_number": 1,
"marked_at": "2026-12-14T17:05:00Z"
}
}partner.enrolled
{
"id": "<delivery uuid>",
"event": "partner.enrolled",
"occurred_at": "2026-10-09T15:00:00Z",
"partner_id": "6f1d2c3b-4a59-4e8f-9b7a-0c1d2e3f4a5b",
"partner_email": "mike@example.com",
"partner_first_name": "Mike",
"partner_last_name": "Torres",
"partner_company": "Torres Exteriors",
"partner_phone": "+17205550188",
"partner_code": "K7Q2M9AB",
"partner_kind": "customer",
"partner_tier": "rookie",
"partner_paid_count": 0,
"partner_status": "invited",
"partner_w9_status": "not_requested",
"referral_link": "https://partners.roleplayray.com/r/K7Q2M9AB",
"portal_link": "https://partners.roleplayray.com/portal",
"owner_email": "dave@roleplayray.com",
"event_type": "partner.enrolled",
"source": "checkout",
"join_link": "https://partners.roleplayray.com/join/K7Q2M9AB",
"partner": {
"id": "6f1d2c3b-4a59-4e8f-9b7a-0c1d2e3f4a5b",
"partner_code": "K7Q2M9AB",
"kind": "customer",
"first_name": "Mike",
"last_initial": "T",
"company_name": "Torres Exteriors",
"email": "mike@example.com",
"joined": false,
"referral_link": "https://partners.roleplayray.com/r/K7Q2M9AB",
"join_link": "https://partners.roleplayray.com/join/K7Q2M9AB",
"portal_link": "https://partners.roleplayray.com/portal"
}
}Verifying a webhook
Read the raw body as text. Join the timestamp header, a period, and the raw body. HMAC-SHA256 it with the webhook secret shown once when the webhook was added, hex encode, prefix sha256=, and compare in constant time. Reject anything older than five minutes. Answer any 2xx within ten seconds; anything else is retried after 1, 5, 15, and 30 minutes. Use the delivery id to ignore repeats.
import { createHmac, timingSafeEqual } from "node:crypto";
function verify(rawBody, timestamp, signature, secret) {
const expected = "sha256=" + createHmac("sha256", secret).update(timestamp + "." + rawBody).digest("hex");
return expected.length === signature.length && timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
}Questions
Write to Support@RolePlayRay.com and include the event id from the response.