Questionnaire
A Questionnaire is an immutable snapshot. Every call returns a new snapshot; the old one never changes.
let q = await client.start('cyber');q = await q.answer({ 'US state': 'Ohio' });Reference
Section titled “Reference”Fields
Section titled “Fields”id: the questionnaire id. Store it to resume later.questions: the outstanding questions, each{ field, name, prompt, type, required, options, search?, rules, ... }.sections: ordered{ id, title? }groups.[]when the server sends none.errors: validation failures for the last answers, as data.ready:trueonce the server offers quotes. Narrows the type: only a ready snapshot hasquotes.recommendations: products to quote, on a recommendation questionnaire. See below.questionnaire:{ name, version }.raw: the response body, untouched.
q.answer(...)
Section titled “q.answer(...)”Sends answers in one PATCH. Three forms:
await q.answer('US state', 'Ohio');await q.answer({ 'US state': 'Ohio', 'Business owner': 'yes' });await q.answer([{ field: 'US state', value: 'Ohio' }]);- Keys are question
fields, notnames. - Values are wire values: dates
YYYY-MM-DD, phones E.164 (+12165550123), currency as plain numbers. The session’sencodeconverts UI values for you.
Returns Promise<Questionnaire>: the snapshot from this call’s response.
Caveats: calls on the same questionnaire are queued and sent one at a time, in order. A rejected value is not an exception: check errors.
q.refresh()
Section titled “q.refresh()”Re-reads the questionnaire. Returns Promise<Questionnaire>.
q.searchTrade(text)
Section titled “q.searchTrade(text)”Searches trades through the trade question’s search template.
const { results } = await q.searchTrade('handyman');q = await q.answer('Primary trade', results[0].value);Returns Promise<{ results: TradeResult[]; searchId }>. Each result has value, label, definition? and blocked?. Submit value; never submit a blocked trade.
recommendations
Section titled “recommendations”On a recommendation questionnaire, once trade and US state are answered: { vertical, title, start(options?) }[]. start() returns a quoting questionnaire seeded with the answers carried over.
Answer until ready
Section titled “Answer until ready”while (!q.ready) { const values = collectAnswers(q.questions); // your UI q = await q.answer(values); if (q.errors.length) showErrors(q.errors);}const quoteSet = await q.quotes.wait();Troubleshooting
Section titled “Troubleshooting”A question I answered came back
Section titled “A question I answered came back”Changing an answer can retract dependent questions, and the server asks for them again. Render q.questions after every response.
ValidationError (422)
Section titled “ValidationError (422)”You sent a field the server doesn’t know, or a malformed body. Check you’re using field, not name.