For landings with their own pages — route on one page, calendar on another, contact details on the last — and no backend. Each page saves its answers into one lead draft straight from the visitor's browser; the last page submits it. We run the same checks as the widget form and forward the same lead to the CRM pipeline.
<script src="https://widget.bdiapps.travel-insides.com/widget/lead.js"></script>
<script>
// route page
await QuoteLead.save({ trip: { type: 'round', origin: 'JFK', destination: 'LHR' } })
// calendar page
await QuoteLead.save({ trip: { departDate: '2026-12-01', returnDate: '2026-12-15' } })
// contact page
await QuoteLead.save({ contact: { email: 'jane@example.com', phone: '2125551234', countryCode: '+1' } })
const lead = await QuoteLead.submit() // { ok: true, id: 'Q-…', leadId: 5480001 }
</script>
https://widget.bdiapps.travel-insides.com · testing: https://widget.dev.marketing.bdi-kiv.dev./cabinet, admin sign-in), section Lead API landings, add the landing's web address, e.g. https://flights.businessclass.com. Subdomain wildcards work: https://*.businessclass.com.403), and browsers won't hand our replies to other sites.These are the calls lead.js makes for you; use them directly if you prefer your own code. They are plain JSON calls from the browser, no headers beyond Content-Type: application/json.
Body: any of trip, contact, attribution (see Fields), or {}. Reply 201:
{
"ok": true,
"draftId": "Zx3kP0qL7vB2mN9sT4yQ8w",
"expiresAt": "2026-10-17T10:15:00.000Z",
"trip": { "type": "round", "origin": "JFK", "destination": "LHR" },
"contact": {},
"attribution": {},
"missing": [
"trip.departDate is required",
"trip.returnDate is required for a round trip",
"contact.email is required",
"contact.phone is required"
]
}
Body: only the fields this page collected. They are merged into the draft field by field — a field you don't send keeps its value; sending a field again replaces it; send "" to clear a text field. trip.flights and attribution.utm are replaced as a whole. Reply 200 with the same shape as above.
The submit reply also carries draft — the trip, contact, attribution and answers that were sent — so the last page can build its offers search from one place. Submitting the same draft again returns the same reply, brought up to date, and sends nothing again (after a restart of our server the repeated reply has draft: null).
Returns the draft and its missing list — useful to decide which page to show next.
No body. Runs every check; when nothing is missing the lead is forwarded and the draft is closed. It must come at least 3 seconds after the draft started. The reply waits until the CRM lead exists (usually 5–15 seconds, at most 25) and carries its id as leadId. Reply 200:
{ "ok": true, "id": "Q-MGX4K2-7FQA", "leadId": 5480001, "state": "delivered", "message": "Thanks! A travel expert will call you back shortly with your fare." }
id is our receipt number. leadId is the CRM lead — a new one, or the visitor's open lead for the same trip from the last 3 days. It is null when the CRM did not answer within 25 seconds or refused the lead; the request is still received.
state says where the lead is: delivered — the CRM pipeline took it (with leadId when it gave one); queued — the pipeline has not taken it yet (it was slow or down), we keep the lead and keep sending it, and leadId is null for now. Submitting the same draft again, or reading it, gives the current state and the lead id once it has arrived, also after a restart of our server, and sends nothing again. A repeated submit answers 503 with state: "failed" when the lead could not be delivered within 48 hours (the draft can then be submitted again), and 500 with state: "unknown" when we no longer have a record of it.
When something is missing, the reply is 422 and the draft stays open so you can send the missing fields and submit again:
{ "ok": false, "message": "contact.phone is required", "problems": ["contact.phone is required"] }
trip| Field | Type | Default | Notes |
|---|---|---|---|
type | round | oneway | multi | — | Required before submit. |
origin | IATA, 3 letters | — | Round / one-way. Any case; sent upper-case. |
destination | IATA, 3 letters | — | Round / one-way. Must differ from origin. |
departDate | YYYY-MM-DD | — | Round / one-way. Not in the past. |
returnDate | YYYY-MM-DD | — | Round trip only. On or after departDate. |
flights | array of {origin, destination, departureDate} | — | Multi-city only: 2–5 legs in date order. |
cabin | economy | premium | business | first | business | Any page; optional. |
adults / children / infants | integer 0–9 | 1 / 0 / 0 | 1–9 travellers in total; at least 1 adult or child; infants need an adult. |
contact| Field | Type | Notes |
|---|---|---|
name | string ≤ 80 | Optional. |
email | string ≤ 120 | Mandatory when the key says so. Checked whenever sent. |
phone | string ≤ 25 | Mandatory when the key says so. Digits, with or without spaces; at least 5 digits. |
countryCode | + and 1–4 digits | Dialling code for phone, e.g. "+1". Leave it off if phone already starts with +. |
A landing that calls QuoteLead.showConsent(el) (or sends attribution.consentShown: true) has shown our consent line. A draft with a valid email or phone is reported as unsent after 15 minutes without a submit; the report says whether the line was shown.
attribution (all optional)| Field | Notes |
|---|---|
sessionId | Your visitor/session id, passed to the lead. Default: api-{draftId}. |
originUrl | The landing page URL the lead came from. lead.js fills it (and utm from the page URL) when the draft starts. |
infoText | Free text shown with the lead (campaign, offer). |
currency | ISO code, default USD. |
partnerId, source | Attribution tags. |
utm | {utm_source, utm_medium, utm_campaign, utm_term, utm_content} |
visitorId | The visitor id cookie, if your site has one. |
answers (optional)A free-form box for anything a later page needs — e.g. quiz preferences for the offers search: {"stops": "nonstop", "departureTime": "morning"}. Up to 30 values; names start with a letter (letters, digits, _ . -, ≤ 40 characters); each value is text (≤ 200 characters), a number or true/false. Saved answers are merged by name and come back on every save, on QuoteLead.get() and in the submit reply. They are kept with the draft only — not shown to sales in the CRM.
"2") are accepted. Request bodies are limited to 16 KB.| Check | On every save (POST / PATCH) | On submit |
|---|---|---|
| Field format (IATA, dates, enums, lengths) | Yes — 400, nothing saved | — |
| Date not in the past | Yes — 400 | Yes |
| Email / phone valid (when sent) | Yes — 400 | Yes |
| Route and dates complete for the trip type | Shown in missing | Yes — 422 |
| Return on/after departure, legs in date order | Shown in missing | Yes — 422 |
| Travellers (1–9, infant needs adult) | Shown in missing | Yes — 422 |
| Mandatory contact per key | Shown in missing | Yes — 422 |
| At least one of email / phone | Shown in missing | Yes — 422 (always, whatever the key) |
Four pages, round trip, landing set to "email + phone".
// page 1
await QuoteLead.save({ trip: { type: 'round', origin: 'JFK', destination: 'LHR' } })
// page 2
await QuoteLead.save({ trip: { departDate: '2026-12-01', returnDate: '2026-12-15' } })
// page 3
await QuoteLead.save({ trip: { adults: 2, children: 1, cabin: 'business' } })
// page 4
await QuoteLead.save({ contact: { name: 'Jane Doe', email: 'jane@example.com',
phone: '2125551234', countryCode: '+1' } })
await QuoteLead.submit()
Landing set to "email only". The contact page sends just the email.
await QuoteLead.save({ contact: { email: 'jane@example.com' } })
await QuoteLead.submit() // ok
Landing set to "phone only".
await QuoteLead.save({ contact: { phone: '7911123456', countryCode: '+44' } })
await QuoteLead.submit() // ok
Send it with the route — or on the last page with the contact. Order doesn't matter.
await QuoteLead.save({ trip: { type: 'round', cabin: 'first',
origin: 'LAX', destination: 'NRT' } })
No return date.
await QuoteLead.save({ trip: { type: 'oneway', origin: 'MIA',
destination: 'MAD', departDate: '2026-11-20' } })
Send the full list of legs; it replaces any earlier list.
await QuoteLead.save({ trip: { type: 'multi', flights: [
{ origin: 'JFK', destination: 'LHR', departureDate: '2026-12-01' },
{ origin: 'LHR', destination: 'CDG', departureDate: '2026-12-06' },
{ origin: 'CDG', destination: 'JFK', departureDate: '2026-12-12' } ] } })
Every save returns the draft with its missing list.
const draft = await QuoteLead.save({ trip: { type: 'round' } })
draft.missing // ['trip.origin is required', ...]
A rejected save or submit throws; show message or use problems.
try { await QuoteLead.submit() }
catch (e) { showError(e.message) /* e.status, e.problems */ }
lead.js keeps the draft id in that visitor's browser tab only, so 100 people on the landing at the same time never share or overwrite a draft, and each submit creates (or reuses) only that visitor's lead. Pass your own visitor or session id as attribution.sessionId on the first save to tie the lead to your analytics; without it we use api-{draftId}. A new browser tab starts a new draft.lead.js keeps everything saved so far in the tab's session storage and quietly starts a new draft when the old one is gone.Every error reply is {"ok": false, "message": "…"}; validation errors add a problems list. lead.js turns them into a rejected promise with message, status and problems.
| Code | Meaning | What to do |
|---|---|---|
400 | A field has the wrong format, a date is in the past, an email/phone is invalid, or the draft id is malformed. Nothing was saved. | Show the visitor the message; fix and save again. |
403 | The page's web address is not on the cabinet list. | Ask an admin to add the landing's address. |
404 | Draft unknown, expired, or started by another landing. | lead.js starts a new draft by itself. |
409 | Saving into a draft that was already submitted. | Start a new draft for a new request. |
422 | Submit with something missing; problems says what. | Ask for it, save, submit again. |
429 | Too many calls from this visitor, more than 50 open drafts from one visitor address, a second accepted request from the same visitor address within 2 minutes (widget form included), submit sooner than 3 s after the draft started, or the same email/phone accepted 3 times in the last 10 minutes. | For "too fast", lead.js waits and retries; for repeats, treat it as already received. |
500 | Repeated submit of a lead we no longer have a record of (state: "unknown"). | Treat it as not confirmed; ask the visitor to send the request again. |
503 | The server holds too many open drafts overall; or (on submit) the lead could be neither stored nor sent right now, so nothing was kept; or (repeated submit) the lead could not be delivered (state: "failed"). | Retry later; the same draft can be submitted again. |
On submit we send this record to the lead webhook — the same shape the widget form produces, plus channel and api_landing_id. ip is the visitor's address.
{
"id": "Q-MGX4K2-7FQA",
"receivedAt": "2026-10-16T10:15:00.000Z",
"ip": "203.0.113.7",
"visitor_id": null,
"originAllowed": true,
"contact": { "name": "Jane Doe", "email": "jane@example.com", "phone": "2125551234", "countryCode": "+1" },
"partner_id": null,
"source": null,
"utm": { "utm_source": "google" },
"payload": {
"query": {
"payload": {
"project": "businessclass", "cabin": "C", "adt": "1", "chd": "0", "inf": "0", "currency": "USD",
"flight": [
{ "origin": "JFK", "destination": "LHR", "departureDate": "2026-12-01" },
{ "origin": "LHR", "destination": "JFK", "departureDate": "2026-12-15" }
],
"trip_type": "RT"
},
"sessionId": "abc-123"
},
"platform": "landing",
"origin_url": "https://flights.businessclass.com/details",
"info_text": "",
"partner_id": null,
"source": null,
"utm": { "utm_source": "google" }
},
"channel": "api",
"api_landing_id": "a1B2c3D4e5F6"
}
<script src="https://widget.bdiapps.travel-insides.com/widget/lead.js"></script>
// e.g. the calendar page's "Continue" button
document.querySelector('#continue').addEventListener('click', async () => {
try {
await QuoteLead.save({ trip: { departDate: depart.value, returnDate: ret.value } })
location.href = '/travellers'
} catch (e) {
errorBox.textContent = e.message
}
})
// the contact page
form.addEventListener('submit', async (ev) => {
ev.preventDefault()
try {
await QuoteLead.save({ contact: { name: name.value, email: email.value } })
await QuoteLead.submit()
location.href = '/thank-you'
} catch (e) {
errorBox.textContent = e.message
}
})
const API = 'https://widget.bdiapps.travel-insides.com/api/v1'
const post = (method, path, body) => fetch(API + path, {
method, headers: body ? { 'Content-Type': 'application/json' } : {}, body: body ? JSON.stringify(body) : undefined,
}).then((r) => r.json())
const draft = await post('POST', '/drafts', { trip: { type: 'round', origin: 'JFK', destination: 'LHR' } })
sessionStorage.setItem('draftId', draft.draftId) // keep it across the landing's pages
await post('PATCH', '/drafts/' + draft.draftId, { contact: { email: 'jane@example.com' } })
const lead = await post('POST', '/drafts/' + draft.draftId + '/submit')
QuoteLead reference| Call | Returns |
|---|---|
QuoteLead.save(fields) | The draft (draftId, saved fields, missing). Starts a draft on first use. |
QuoteLead.submit() | { ok, id, leadId, message }; clears the saved draft. |
QuoteLead.get() | The draft, or null if none. |
QuoteLead.reset() | Forgets the draft in this tab. |