Quote Widget
Lead API · v1

Send leads from a multi-page landing

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.

every page of the landing
<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>
No key, nothing secret. Anything in a web page is public, so the API uses none. A landing is recognised by its web address, which an admin adds in the widget cabinet. The calls do show in the visitor's Network tab — they carry only the visitor's own answers. Base URL — production: https://widget.bdiapps.travel-insides.com · testing: https://widget.dev.marketing.bdi-kiv.dev.
Allowed landings

Add the landing's address in the cabinet

  • In the widget cabinet (/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.
  • Each entry fixes two things for that landing: the project the lead belongs to, and which contact field is mandatory — email + phone, phone only, or email only.
  • Calls from any other address are refused (403), and browsers won't hand our replies to other sites.
  • Removing the entry stops that landing immediately; its open drafts can no longer be used.
  • Abuse protection works without a secret, like the widget form: limits per visitor, a submit no sooner than 3 seconds after the draft started, one submit per draft, and a limit on the same email/phone.
Endpoints

Four calls

Start a draft

POST /api/v1/drafts

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"
  ]
}

Save a page

PATCH /api/v1/drafts/{draftId}

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).

Read a draft

GET /api/v1/drafts/{draftId}

Returns the draft and its missing list — useful to decide which page to show next.

Submit

POST /api/v1/drafts/{draftId}/submit

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"] }
Fields

Everything a draft can hold

trip

FieldTypeDefaultNotes
typeround | oneway | multi—Required before submit.
originIATA, 3 letters—Round / one-way. Any case; sent upper-case.
destinationIATA, 3 letters—Round / one-way. Must differ from origin.
departDateYYYY-MM-DD—Round / one-way. Not in the past.
returnDateYYYY-MM-DD—Round trip only. On or after departDate.
flightsarray of {origin, destination, departureDate}—Multi-city only: 2–5 legs in date order.
cabineconomy | premium | business | firstbusinessAny page; optional.
adults / children / infantsinteger 0–91 / 0 / 01–9 travellers in total; at least 1 adult or child; infants need an adult.

contact

FieldTypeNotes
namestring ≤ 80Optional.
emailstring ≤ 120Mandatory when the key says so. Checked whenever sent.
phonestring ≤ 25Mandatory when the key says so. Digits, with or without spaces; at least 5 digits.
countryCode+ and 1–4 digitsDialling 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)

FieldNotes
sessionIdYour visitor/session id, passed to the lead. Default: api-{draftId}.
originUrlThe landing page URL the lead came from. lead.js fills it (and utm from the page URL) when the draft starts.
infoTextFree text shown with the lead (campaign, offer).
currencyISO code, default USD.
partnerId, sourceAttribution tags.
utm{utm_source, utm_medium, utm_campaign, utm_term, utm_content}
visitorIdThe 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.

Unknown fields are ignored. Numbers sent as strings ("2") are accepted. Request bodies are limited to 16 KB.
Validation rules

When each check runs

CheckOn every save (POST / PATCH)On submit
Field format (IATA, dates, enums, lengths)Yes — 400, nothing saved—
Date not in the pastYes — 400Yes
Email / phone valid (when sent)Yes — 400Yes
Route and dates complete for the trip typeShown in missingYes — 422
Return on/after departure, legs in date orderShown in missingYes — 422
Travellers (1–9, infant needs adult)Shown in missingYes — 422
Mandatory contact per keyShown in missingYes — 422
At least one of email / phoneShown in missingYes — 422 (always, whatever the key)
Cases

Common landing layouts

A. Route → calendar → travellers → contact

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()

B. Email-only landing

Landing set to "email only". The contact page sends just the email.

await QuoteLead.save({ contact: { email: 'jane@example.com' } })
await QuoteLead.submit()                     // ok

C. Phone-only landing

Landing set to "phone only".

await QuoteLead.save({ contact: { phone: '7911123456', countryCode: '+44' } })
await QuoteLead.submit()                     // ok

D. Cabin on the first page

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' } })

E. One-way

No return date.

await QuoteLead.save({ trip: { type: 'oneway', origin: 'MIA',
                               destination: 'MAD', departDate: '2026-11-20' } })

F. Multi-city

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' } ] } })

G. Show what is still missing

Every save returns the draft with its missing list.

const draft = await QuoteLead.save({ trip: { type: 'round' } })
draft.missing  // ['trip.origin is required', ...]

H. Handling a problem

A rejected save or submit throws; show message or use problems.

try { await QuoteLead.submit() }
catch (e) { showError(e.message) /* e.status, e.problems */ }
Many visitors at once. Every visitor gets their own draft: 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.
Lost drafts are rebuilt. A draft lives 24 hours once it holds an email or phone, 2 hours before that; a server restart drops open ones. 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.
Errors & limits

Status codes

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.

CodeMeaningWhat to do
400A 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.
403The page's web address is not on the cabinet list.Ask an admin to add the landing's address.
404Draft unknown, expired, or started by another landing.lead.js starts a new draft by itself.
409Saving into a draft that was already submitted.Start a new draft for a new request.
422Submit with something missing; problems says what.Ask for it, save, submit again.
429Too 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.
500Repeated 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.
503The 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.

Limits

  • Per visitor: 30 new drafts and 120 saves / reads a minute, 5 submits per 10 minutes.
  • A draft lives 24 hours once it holds an email or phone (2 hours before that); submitting it again returns the first result brought up to date, and sends nothing again; up to 5,000 open drafts per landing and 50 per visitor address.
What we forward

The same lead as the widget form

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"
}
Code examples

From the landing's pages

With lead.js (recommended)

<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
  }
})

Plain fetch (without lead.js)

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

CallReturns
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.