import { Flow9 } from "@flow9/sdk";
const flow9 = new Flow9({
security: { apiKeyAuth: process.env.F9_KEY! },
// serverURL defaults to production; point it at another environment if needed.
});
// Reachability — no auth needed.
const health = await flow9.health.getHealth();
console.log(health.result.data?.status); // "ok"
// Create a lead. The Idempotency-Key makes a retry safe: the same key + same body
// replays the original response instead of creating a second lead.
const created = await flow9.leads.createLead({
idempotencyKey: crypto.randomUUID(),
body: { firstName: "Ada", lastName: "Lovelace", email: "ada@example.com" },
});
const lead = created.result.data!;
console.log("created lead", lead.id);
// Add a note to it, then list its activities.
await flow9.records.createRecordNote({
object: "leads",
id: lead.id,
body: { content: "Imported from the quickstart." },
});
const activities = await flow9.records.listRecordActivities({ object: "leads", id: lead.id, limit: 5 });
console.log(activities.result.data?.activities);