Leads and your CRM
Other CRMs
Send leads from your site to any CRM with an API, from the same server route the Follow Up Boss, Sierra Interactive and Sure Send examples use.
Ruuster connects with Follow Up Boss, Sierra Interactive and Sure Send, and the examples send leads to each of them. If your brokerage uses another CRM, your site sends leads to it the same way: the form posts to your own server route, and the route posts to your CRM's API with your CRM's key.
Steps
- Find your CRM's API reference for creating a lead or contact: the URL, the authentication header and the body fields for name, email, phone, source, tags and a note.
- Copy
lib/crm.tsfrom the examples. KeepsameOrigin,parseLeadand the checks at the top ofhandleLead: the origin check, the honeypot, an email or phone, and the contact consent box. - Add a branch that builds your CRM's body from the
LeadSubmissionand posts it withfetch. UsecrmProperty(listing, url)from@ruuster/idx/crmfor the listing facts: it leaves the street out when the address is hidden and leaves the price out rather than sending 0. UsenurtureTags(lead)for the tags, so they follow the alerts box, andrequestLines(lead, property)for a plain-words note. - Set the source to your
SITE_NAME. CallassertSiteSource(SITE_NAME)first; it refuses the names reserved for Ruuster's own activity. - Answer the form with the same sentences (
MESSAGESinlib/crm.ts), and pass a 429 and itsRetry-Afteron. - Send a test lead from your site on
localhostand find it in your CRM.
These are the shared pieces your branch can use:
lib/crm.ts
/** The JSON the recipe forms post (LeadSubmission), checked field by field. Null when it is not one. */
export function parseLead(body: unknown): LeadSubmission | null {
if (!body || typeof body !== "object") return null;
const b = body as Record<string, unknown>;
if (b.kind !== "registration" && b.kind !== "tour" && b.kind !== "contact") return null;
const consent = (b.consent ?? {}) as Record<string, unknown>;
const page = (b.page ?? {}) as Record<string, unknown>;
const tour = b.tour && typeof b.tour === "object" ? (b.tour as Record<string, unknown>) : null;
const listing = b.listing && typeof b.listing === "object" ? (b.listing as Record<string, unknown>) : null;
const listingId = listing ? str(listing.id, 100) : "";
return {
kind: b.kind,
firstName: str(b.firstName, 100),
lastName: str(b.lastName, 100),
email: str(b.email, 200),
phone: strOrNull(b.phone, 40),
message: strOrNull(b.message, 2000),
tour: tour ? { date: strOrNull(tour.date, 40), time: strOrNull(tour.time, 40) } : null,
listing: listingId ? { id: listingId, mlsNumber: strOrNull(listing?.mlsNumber, 40), url: strOrNull(listing?.url, 1000) } : null,
consent: { contact: consent.contact === true, alerts: consent.alerts === true, text: str(consent.text, 1000) },
page: { url: str(page.url, 1000), referrer: strOrNull(page.referrer, 1000) },
attribution: parseAttribution(b.attribution),
// The agent and lead type a form names (for example a form on one agent's own page). Set or drop
// them here if you'd rather decide on your server; left out, your CRM's lead routing assigns the lead.
agent: parseAgent(b.agent),
leadType: b.leadType === "buyer" || b.leadType === "seller" || b.leadType === "both" ? b.leadType : null,
website: str(b.website, 200),
};
}
function campaignIds(a: Record<string, unknown>): CampaignIds {
return {
utmSource: strOrNull(a.utmSource, 200),
utmMedium: strOrNull(a.utmMedium, 200),
utmCampaign: strOrNull(a.utmCampaign, 200),
utmTerm: strOrNull(a.utmTerm, 200),
utmContent: strOrNull(a.utmContent, 200),
gclid: strOrNull(a.gclid, 200),
fbclid: strOrNull(a.fbclid, 200),
msclkid: strOrNull(a.msclkid, 200),
};
}
function touch(raw: unknown): CampaignTouch | null {
if (!raw || typeof raw !== "object") return null;
const t = raw as Record<string, unknown>;
return { ...campaignIds(t), landingPage: strOrNull(t.landingPage, 1000), referrer: strOrNull(t.referrer, 1000), at: strOrNull(t.at, 40) };
}
/** Where the visitor came from: this visit's campaign ids, landing page and referrer, the form page, and the first and last touch. */
export function parseAttribution(raw: unknown): LeadAttribution {
const a = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
return {
...campaignIds(a),
referrer: strOrNull(a.referrer, 1000),
landingPage: strOrNull(a.landingPage, 1000),
formPage: strOrNull(a.formPage, 1000),
firstTouch: touch(a.firstTouch),
lastTouch: touch(a.lastTouch),
};
}
function parseAgent(raw: unknown): LeadAgent | null {
if (!raw || typeof raw !== "object") return null;
const a = raw as Record<string, unknown>;
const agent = { id: strOrNull(typeof a.id === "number" ? String(a.id) : a.id, 100), email: strOrNull(a.email, 200), name: strOrNull(a.name, 200) };
return agent.id || agent.email || agent.name ? agent : null;
}
lib/crm.ts
/** Only your own pages may post leads: the browser's Origin header must be exactly SITE_ORIGIN. */
export function sameOrigin(request: Request, siteOrigin: string | undefined): boolean {
if (!siteOrigin) return false;
const origin = request.headers.get("origin");
if (!origin) return false;
try {
return new URL(origin).origin === new URL(siteOrigin).origin;
} catch {
return false;
}
}
/** A listing URL from the form counts only when it is a page on your own site. */
export function ownUrl(url: string | null | undefined, siteOrigin: string | undefined): string | null {
if (!url || !siteOrigin) return null;
try {
const u = new URL(url);
return u.origin === new URL(siteOrigin).origin ? u.toString() : null;
} catch {
return null;
}
}
Getting the lead to Ruuster
AI Nurture works from the CRMs connected to Ruuster. If your CRM is not one of them, ask your Ruuster contact which connection fits your brokerage before you launch.