createClient
createClient creates a client that starts, resumes and recommends questionnaires.
const client = createClient(options)Reference
Section titled “Reference”createClient(options)
Section titled “createClient(options)”import { apiKey, createClient } from '@partner-sdk/core';
const client = createClient({ baseUrl: 'https://api.example.com', auth: apiKey(key),});Options
Section titled “Options”baseUrl: the API origin (origin only, no path). Links the server returns on other origins are rebased onto it.auth(optional): an auth hook.apiKey(key, header = "x-api-key")sends a key header. Auth is only sent tobaseUrl’s origin.fetch(optional): afetchimplementation. Defaults to the global.timeoutMs(optional): per-attempt timeout. Default30000.retry(optional):{ retries: 2, baseMs: 250, capMs: 5000, maxRetryAfterMs: 30000 }by default, orfalse. Only GET, PUT and PATCH are retried, on network errors, 429, 502, 503 and 504.hooks(optional):onRequest,onResponse,onRetry,onRebase. Hooks never receive bodies.transport(optional): your own transport fromcreateTransport, in place of the options above.startPath(optional): default/api/v0/application.recommendPath(optional): default/api/v0/product_recommendation.
Returns
Section titled “Returns”A Client.
client.start(vertical, options?)
Section titled “client.start(vertical, options?)”Creates a quoting questionnaire for a product.
const q = await client.start('cyber');vertical: a product id, such as"cyber"or"usa". Your editor suggests known ids; the server decides what’s valid.options.discover(optional): read the API root first and reject unknown verticals before any POST.options.signal(optional): anAbortSignal.
Returns a Promise<Questionnaire>. See Questionnaire.
client.resume(id, options?)
Section titled “client.resume(id, options?)”Re-opens a questionnaire, for example after a page reload.
const q = await client.resume(storedId);Returns a Promise<Questionnaire> with the outstanding questions only. The API never returns stored answers; you keep those.
Caveats: an unknown or expired id rejects with an ApiError (401, 403, 404 or 410).
client.recommend(options?)
Section titled “client.recommend(options?)”Creates a product recommendation questionnaire. See Recommend a product.
Returns a Promise<Questionnaire>.
client.listVerticals(options?)
Section titled “client.listVerticals(options?)”Lists the products the API offers, from the API root. Cached per client; pass refresh: true to re-fetch.
Returns a Promise<Vertical[]>, each { id, name, start(options?) }.
client.searchTrade(template, text, options?)
Section titled “client.searchTrade(template, text, options?)”Searches trades with a question’s search template, through the client’s transport. Use this when your UI holds the template itself; otherwise use q.searchTrade(text) or session.searchTrade(name, text).
Returns Promise<{ results: TradeResult[]; searchId }>.
Discover products first
Section titled “Discover products first”const verticals = await client.listVerticals();const cyber = verticals.find((v) => v.id === 'cyber');const q = await cyber?.start();Use your own fetch
Section titled “Use your own fetch”const client = createClient({ baseUrl, fetch: myInstrumentedFetch });Observe requests without seeing answers
Section titled “Observe requests without seeing answers”const client = createClient({ baseUrl, hooks: { onResponse: ({ method, status, durationMs, requestId }) => metrics.record(method, status, durationMs, requestId), },});Troubleshooting
Section titled “Troubleshooting”I get UnauthorizedError (401)
Section titled “I get UnauthorizedError (401)”Deployed environments sit behind an API Gateway that needs x-api-key. Pass auth: apiKey(key). Local servers and the mock API need no key.
My browser blocks requests with a CORS error
Section titled “My browser blocks requests with a CORS error”The V0 API doesn’t send CORS headers yet. For local work, run the mock with ALLOWED_ORIGINS=http://localhost:4321 bun start.