Your backend starts the Run and issues a Customer Token; the browser uses both to show the Funnel. The backend Key needs funnels:run, sessions:create and customers:write. A Run uses the permissions of the Key that started it: Paywall and Offering steps need entitlements:read; buying from a Paywall also needs billing:write (quote, confirm and cancel) and billing:read (settlement and recovery reads); claiming or showing Coupons needs offers:resolve. In the Console's Create Key dialog, "Use Funnel start permissions" selects all of them: funnels:run, sessions:create, customers:write, entitlements:read, offers:resolve, billing:read, billing:write.
server/funnel.tsTypeScript
1import { createFunnelStartClient, createLongplayServer } from"@tinkerlandai/longplay-sdk/server";23const options = {4 baseUrl: process.env.LONGPLAY_API_URL!,5 apiKey: process.env.LONGPLAY_SERVER_KEY!,6 scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox"asconst },7};8const funnels = createFunnelStartClient(options);9const longplay = createLongplayServer(options);1011exportasyncfunctionstartOnboarding(verifiedUserId: string, requestId: string) {12const started = await funnels.start({13 funnelId: process.env.LONGPLAY_FUNNEL_ID!,14 requestId, // persisted; reuse it with the same input after an unknown result15 customer: { type: "externalUserId", value: verifiedUserId },16 locale: "en",17 parameters: {18 source: "signup",19// Required when the Funnel shows a Paywall.20 commerce: { provider: "stripe", currency: "USD" },21 },22 });23const customerSession = await longplay.createCustomerSession(started.customerId!);24return { runToken: started.runToken, started, customerSession };25}
When the Funnel shows a Paywall, the start must include parameters.commerce with provider and currency. Without it the request returns 400 and no Run is created.
Save the requestId; retrying with the same value after a lost response returns the same Run.
A paused Funnel refuses new starts with 409 CONFLICT; show it as temporarily unavailable. Replaying the original requestId still returns the original Run.
Payments and coupon grants in a Funnel run on the server; closing the browser does not stop accepted work.
When a Funnel waits at a node, your backend submits the external event; eventId deduplicates it.
eventName must exactly match the wait node's event name, including case. Event names start with a letter, contain only letters, digits, _, . and -, and are at most 64 characters, for example kyc_approved or kyc.approved.
signal.tsTypeScript
1import { createFunnelOrchestrationClient } from"@tinkerlandai/longplay-sdk/server";23const orchestration = createFunnelOrchestrationClient({4 baseUrl: process.env.LONGPLAY_API_URL!,5 apiKey: process.env.LONGPLAY_SERVER_KEY!,6 scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox" },7});89// eventId is persisted with your business event, so retries are deduplicated.10exportasyncfunctionreportKycApproved(runId: string, eventId: string) {11const { accepted } = await orchestration.signal({12 runId,13 nodeId: "wait_for_kyc",14 eventName: "kyc_approved",15 eventId,16 data: { level: "full" },17 });18return accepted ? orchestration.readResults(runId) : null;19}
A Funnel published in Local mode can start directly in the browser without waiting for server evaluation. Its rules are visible to everyone, so use server evaluation for eligibility or pricing decisions.
local-funnel.tsTypeScript
1import {2 createConfigurationSync,3 createLocalFunnelClient,4 showFunnelRun,5} from"@tinkerlandai/longplay-sdk";67const baseUrl = "https://api.longplayai.com";8const configuration = createConfigurationSync({9 origin: baseUrl,10 scope: { projectId: "<APP_UUID>", environment: "sandbox", environmentId: "<ENVIRONMENT_UUID>" },11});1213exportasyncfunctionshowLocalFunnel(14 container: HTMLElement,15 customerToken: string,16 requestId: string,17) {18const flow = awaitcreateLocalFunnelClient({19 baseUrl,20 configuration,21 funnelId: "<PUBLISHED_FUNNEL_UUID>",22 credential: customerToken,23 });24const started = await flow.start({ requestId, locale: "en", parameters: {} });25// Keep started.runToken to restore the same Run later with flow.restore(runToken).26returnshowFunnelRun(container, { client: started.controller });27}