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.

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.

FieldTypeRequiredNotes
event"customer.paid" | "roster.loaded" | "company.updated" | "customer.canceled"yes
event_idstringyesUnique per event, for example the Stripe event id. A retry with the same id changes nothing.
occurred_atstring (date-time)yes
customerobjectyes
referral_codeobjectnocustomer.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"nocustomer.paid: where the code was captured.
amount_centsintegernocustomer.paid: the first charge in cents.
monthly_fee_centsintegernocustomer.paid: the client's monthly platform fee in cents. A Preferred Partner's share is a percent of this.
reps_can_participatebooleannoThe 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.
repsarraynoroster.loaded: the client's sales reps.
owner_emailstring (email)noThe RolePlay Ray team member who owns the account. Defaults to PROGRAM_DEFAULT_REP_EMAIL.
enrollbooleannocustomer.paid: enroll the payer in the Referral Program. Default true.
welcome_delay_daysintegernoHold the welcome email this many days. Default 0.
FieldTypeRequiredNotes
customer.idstringyesThe 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.companystringnoThe client company's name. Required the first time a company is seen.
customer.emailstring (email)nocustomer.paid: the payer's email.
customer.first_namestringno
customer.last_namestringno
customer.phonestringno
{
  "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:

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

FieldTypeRequiredNotes
event_type"contact.created"yes
external_event_idstringyesUnique per event in your system. Retries with the same id are stored once.
occurred_atstring (date-time)yesWhen it happened, ISO 8601 with timezone.
rep_emailstring (email)yesThe 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.

FieldTypeRequiredNotes
data.external_idstringyesRolePlay 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_namestringyes
data.last_namestringyes
data.companystringnoThe referred company's name.
data.emailstring (email)no
data.phonestringnoE.164, for example +15125550142.
data.address1stringno
data.citystringno
data.statestringno
data.postal_codestringno
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.

FieldTypeRequiredNotes
data.external_idstringyesRolePlay 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_namestringyes
data.last_namestringyes
data.companystringnoThe referred company's name.
data.emailstring (email)no
data.phonestringnoE.164, for example +15125550142.
data.address1stringno
data.citystringno
data.statestringno
data.postal_codestringno
data.partner_codestringnoThe 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_emailstring (email)noThe referrer's email, when the code is unknown.
data.partner_phonestringnoE.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"noWhere 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.

FieldTypeRequiredNotes
data.external_idstringyes
data.sale_amount_centsintegeryesThe first charge, in whole cents. 59600 is $596.00.
data.monthly_fee_centsintegernoThe client's monthly platform fee, in whole cents. A Preferred Partner's share is a percent of this.
data.sale_datestring (date)yes
data.sale_type"new" | "upgrade" | "referral"noOptional. 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.

FieldTypeRequiredNotes
data.external_idstringyes
data.canceled_datestring (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.

FieldTypeRequiredNotes
data.external_idstringyes
data.appointment_type"demo" | "onboarding" | "other"yes
data.scheduled_forstring (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.

FieldTypeRequiredNotes
data.external_idstringyes
data.install_datestring (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.

FieldTypeRequiredNotes
data.external_idstringyes
data.completed_datestring (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.

FieldTypeRequiredNotes
data.external_idstringyes
data.paid_datestring (date)yes
data.amount_centsintegerno
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:

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.

FieldOnMeaning
eventevery eventThe event name, the same as event_type.
occurred_atevery eventWhen it happened, ISO 8601 in UTC.
partner_emailevery eventThe partner's email. Use it to find or create the CRM contact.
partner_first_nameevery eventFirst name.
partner_last_nameevery eventLast name.
partner_companyevery eventCompany name, or null.
partner_phoneevery eventPhone in +1 format, or null.
partner_codeevery eventThe partner's code, as in their link.
partner_kindevery eventcustomer (a Referral Program member: a client's leader or rep) or preferred (a Preferred Partner).
partner_tierevery eventrookie, bronze, silver, gold, or platinum, by all-time paid referrals.
partner_paid_countevery eventAll-time paid referrals.
partner_statusevery eventinvited (no sign-in yet), active, or unsubscribed.
partner_w9_statusevery eventnot_requested, requested, or received.
referral_linkevery eventThe partner's personal referral link.
portal_linkevery eventThe partner portal address.
owner_emailevery eventThe RolePlay Ray team member who owns the partner (or, on referral events, the referral).
referral_statusreferral and payout eventsReceived, Signed, Earned, Paid, or Canceled.
previous_referral_statusreferral.status_changed, referral.manual_moveThe status before the move, in the same words.
referred_companyreferral and payout eventsThe referred company's name, or null.
referred_namereferral and payout eventsThe referred person as the referrer knows them, "Jane S."
reward_centsreferral and payout eventsThe reward in cents: the amount paid once paid, the expected amount before that, null when canceled.
reward_dollarsreferral and payout eventsThe 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.