1// Server-side helper. Keep the API key on your backend.2const api = (path: string, body?: object) =>3 fetch("https://api.bundle.social/api/v1" + path, {4 method: body ? "POST" : "GET",5 headers: { "x-api-key": process.env.BUNDLE_SOCIAL_API_KEY!, "Content-Type": "application/json" },6 body: body ? JSON.stringify(body) : undefined,7 }).then((res) => res.json());89// 1. A customer signs up: create a team for their workspace and store team.id.10const team = await api("/team", { name: "Acme Bakery" });11await saveWorkspace(workspace.id, { bundleTeamId: team.id });1213// 2. "Connect accounts" button: send the customer to the hosted connect page.14const { url } = await api("/social-account/create-portal-link", {15 teamId: team.id,16 socialAccountTypes: ["INSTAGRAM", "LINKEDIN", "FACEBOOK"],17 redirectUrl: "https://app.example.com/settings/social",18 logoUrl: "https://app.example.com/logo.png",19 hidePoweredBy: true,20});2122// 3. Composer: import the image the customer picked.23const upload = await api("/upload/from-url", {24 teamId: team.id,25 url: "https://cdn.example.com/spring-menu.jpg",26});2728// 4. Schedule. referenceKey stores your own ID so you can find the post later.29const post = await api("/post", {30 teamId: team.id,31 title: "Spring menu",32 referenceKey: "composer_8812",33 postDate: "2026-05-14T10:00:00.000Z",34 status: "SCHEDULED",35 socialAccountTypes: ["INSTAGRAM", "LINKEDIN"],36 data: {37 INSTAGRAM: { type: "POST", text: "The spring menu is here.", uploadIds: [upload.id] },38 LINKEDIN: { text: "Our spring menu is live.", uploadIds: [upload.id] },39 },40});4142// 5. Webhook: post.published fires when the post ends as POSTED or ERROR.43// Verify the x-signature header (HMAC-SHA256 of the raw body) before trusting the event.44app.post("/webhooks/bundle", async (req, res) => {45 const { type, data } = req.body;46 if (type === "post.published") {47 await updateComposerStatus(data.teamId, data.referenceKey, data.status, data.errors);48 }49 res.sendStatus(200);50});