Case studies

A product launch from a store webhook

A new product in the store becomes a scheduled, multi-channel launch campaign with drip follow-ups — automatically, with a human sign-off.

Kettle & Co. (an illustrative coffee-gear shop) launches a product almost every week. Doing it by hand meant:

  • copying images into four schedulers;
  • rewriting the same copy for each network's limits;
  • forgetting the follow-up post.

Now publishing a product in the store triggers a launch campaign that a marketer reviews in one place.

Flow#

store "product published" webhook
      │
      ▼
launch service ──▶ POST /media/import (product photos, ?wait=true)
      │        ──▶ POST /workspaces/{ws}/campaigns (brief from the product page)
      │        ──▶ LLM drafts 3 posts: teaser, launch, social proof (per-channel variants)
      │        ──▶ POST /validate → fix → POST /posts:batch (submit_for_review, scheduled times)
      │        ──▶ GET /posts/{id}/cost (is the balance enough?)
      ▼
marketer approves in the Review screen ──▶ scheduler publishes ──▶ drip follow-up comments
      │
      └── webhooks: variant.published / variant.failed / billing.low_balance → Slack

1. Import the product images#

POST /media/import fetches a public URL. It is guarded against server-side request forgery and sniffs the content type. With ?wait=true it returns once processing is done, with previews and platform crops ready:

TypeScript
const OB = 'https://api.outboxer.dev/v1';
const H = { Authorization: `Bearer ${process.env.OUTBOXER_API_KEY}`, 'Content-Type': 'application/json' };

async function importImage(ws: string, url: string, alt: string) {
  const res = await fetch(`${OB}/workspaces/${ws}/media/import?wait=true`, {
    method: 'POST',
    headers: { ...H, 'Idempotency-Key': `import:${url}` },   // re-running the hook never duplicates assets
    body: JSON.stringify({ url, alt_text: alt }),
  });
  const media = await res.json();
  if (!res.ok) throw new Error(media.code);                  // e.g. url_not_allowed, unsupported_format
  return media.id as string;                                  // med_…
}

Identical bytes return the existing asset, so the same photo used in several launches is stored once.

2. Create the campaign#

TypeScript
const campaign = await (await fetch(`${OB}/workspaces/${ws}/campaigns`, {
  method: 'POST', headers: { ...H, 'Idempotency-Key': `campaign:${product.id}` },
  body: JSON.stringify({
    name: `Launch: ${product.title}`,
    brief: product.description.slice(0, 2000),               // agents read this before drafting
    objective: 'launch', status: 'active',
    starts_on: launchDay, ends_on: plusDays(launchDay, 7),
    channel_ids: channelIds, labels: ['product'],
    targets: { total_posts: 3 },
  }),
})).json();

3. Draft, validate, and batch-create three posts#

Each post has per-channel variants. On Instagram the link goes into the first comment; on X the text is counted the way X counts it. The drip follow-ups are part of the post:

TypeScript
const launchPost = {
  base: { text: copy.launch, media: mediaIds },
  variants: [
    { channel_id: ig, post_type: 'carousel', options: { first_comment: `Shop it: ${product.url}` } },
    { channel_id: x, text: copy.launchShort },
    { channel_id: li, text: copy.launchLong },
  ],
  campaign_id: campaign.id,
  labels: ['product'],
  schedule: { mode: 'exact', at: `${launchDay} 09:00` },     // workspace timezone
  followups: [
    { delay: '+3h', text: 'Questions about brew ratios? Ask below and our roaster will answer.' },
    { delay: '+1d', text: `Day two: the brewing guide is live → ${product.guideUrl}`, channel_ids: [li] },
  ],
  submit_for_review: true,
};

const check = await (await fetch(`${OB}/workspaces/${ws}/validate`, { method: 'POST', headers: H, body: JSON.stringify(launchPost) })).json();
const errors = check.issues.filter((i: any) => i.severity === 'error');
// errors[].path / hint, e.g. {code: 'text_too_long', path: 'variants[1].text', hint: 'shorten by 12 …'} → ask the LLM to fix

await fetch(`${OB}/workspaces/${ws}/posts:batch`, {
  method: 'POST', headers: { ...H, 'Idempotency-Key': `launch:${product.id}` },
  body: JSON.stringify({ items: [teaser, launchPost, socialProof].map((post) => ({ action: 'create', post })) }),
});

How the requested times and follow-ups are handled:

  • Requested times. The service's key has no posts:approve, so the times are stored as proposed_at. The marketer sees them in the Review screen and confirms them by approving.
  • Rate caps. If a time would break a platform's posting cap, approval answers rate_cap_exceeded with a suggested_at.
  • Follow-ups are checked against each platform's comment limit when the post is created. They go out after publishing, as comments, or as self-replies on X.

4. Make sure the launch can be paid for#

Publishing is paid per channel, from the organization's prepaid credit:

TypeScript
const cost = await (await fetch(`${OB}/posts/${post.id}/cost`, { headers: H })).json();
if (!cost.sufficient) {
  await slack(`Launch "${product.title}" needs ${fmt(cost.due)} of credit, but the balance is ${fmt(cost.balance)}. Top up in Billing.`);
}

There's a second safety net:

  • Pre-flight checks the balance again five minutes before each post. If it's too low, it notifies the workspace's owners while there's still time to top up.
  • A charged post that ultimately fails is refunded automatically.

5. Watch the outcome#

Subscribe once:

Shell
OB=https://api.outboxer.dev/v1   # ADMIN_KEY: an owner or admin's API key
curl -s -X POST $OB/webhooks -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \
  -d '{"workspace_id": "kettle", "url": "https://launch.kettle.example/hooks/outboxer",
       "events": ["variant.published", "variant.failed", "followup.failed", "billing.low_balance"]}'

Then forward variant.failed (with its failure_code, for example channel_auth_failed or insufficient_credits) and every permalink from variant.published to the team channel. Verify the Outboxer-Signature header first; see webhooks.

What this setup gives Kettle & Co.#

  • One review instead of four schedulers. The marketer reviews three posts across every channel in one screen.
  • Formatting handled per network. Images are cropped per platform, links go where each network allows them, and text is counted the way each network counts it.
  • Safe re-runs. If the store sends its webhook twice, nothing is duplicated, because every call carries an idempotency key derived from the product id.
  • Predictable cost, visible before anything is scheduled.