sdk.Leads creates leads in Rechat's CRM from your website — either directly with
capture(), or by binding an existing HTML form with form().
capture(channel, lead)const sdk = new Rechat.Sdk()
sdk.Leads.capture({
lead_channel: '2c55e69d-adbe-42d9-97a5-bedb43783b80'
}, {
first_name: 'John',
last_name: 'Doe',
email: 'john-doe@gmail.com',
phone_number: '+18189191212',
})
.then(lead => console.log('Created lead', lead.id))
.catch(e => console.error(e))
The first argument identifies where the lead goes; the second is the lead itself.
| Field | Description |
|---|---|
lead_channel |
The Rechat lead-channel id to deliver the lead to |
user_id, brand_id |
Attribute the lead to a user / brand |
ad_campaign_id, email_campaign_id, email_campaign_email_id |
Attribute the lead to a campaign |
Any of these fields present in the page URL as rechat_* query parameters
(e.g. ?rechat_ad_campaign_id=…) are collected automatically and merged in — values
you pass explicitly win.
All optional unless noted: first_name, last_name, email, phone_number, tag,
lead_source, note, address, referer_url, mlsid, listing_id, agent_mlsid,
source_type, and assignees — a list of { email, phone_number, first_name, last_name, mlsid, mls } objects identifying agents the lead should be assigned to.
Resolves with the created lead: { id, contact, created_at, lead_channel, source_type }.
If the browser is offline it resolves with { queued: true, … } and the request is
re-sent automatically when the connection returns — see offline sync in the
SDK overview. Unless the tracker is disabled, the new lead is also
identified for activity tracking.
form(element, channel, events) — bind an HTML formWire a form you already have to lead capture. On submit, every named field is collected
into the lead payload and passed to capture() with your channel:
<form id="lead-form">
<input name="first_name">
<input name="last_name">
<input name="email">
<button type="submit">Contact me</button>
</form>
<script>
const sdk = new Rechat.Sdk()
sdk.Leads.form(document.querySelector('#lead-form'), {
lead_channel: '2c55e69d-adbe-42d9-97a5-bedb43783b80'
}, {
validate: (payload) => Boolean(payload.email),
onSuccess: (lead) => console.log('Created', lead.id),
onError: (e) => console.error(e),
})
</script>
| Callback | When |
|---|---|
validate(payload) |
Before submission. Return false to cancel the capture. |
onSuccess(lead) |
The lead was created (or queued offline). |
onError(error) |
The capture failed. |