Customer io b2b lifecycle

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Customer io b2b lifecycle is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Source: https://customer.io/docs/api/

How to use this skill

Skill file

<!--

Source: https://customer.io/docs/api/

Event-driven B2B / product-led lifecycle. Companion to Klaviyo (e-com).

Deeper than marketing-agent's coverage: liquid templating, multi-workspace,

Data Pipelines for activation events, smart send time, broadcasts vs campaigns.

-->

Customer.io B2B Lifecycle — SKILL

Event-driven B2B + product-led lifecycle: campaigns triggered by activation events from your product warehouse (PostHog / Mixpanel / Segment), transactional sends, broadcasts, and smart send time. Customer.io is the SOTA when "user did X in product, send Y" is the spine of your nurture.

When to use

Do not use for: pure e-commerce / DTC lifecycle (use Klaviyo skill); creator-economy newsletter (Beehiiv skill); transactional-only with React Email (Resend/Postmark skill).

Setup

# Customer.io has three APIs:
#   Track API   — events / people / devices (write)
#   App API     — campaigns / segments / broadcasts / transactional (admin)
#   Data Pipelines — Segment-style CDP integration (Sources / Destinations)

# No first-party MCP yet (June 2026); call REST directly via cli-anything.

Auth:

export CIO_SITE_ID="<your_site_id>"                 # https://fly.customer.io/settings/api_credentials
export CIO_TRACK_API_KEY="<basic_auth_password>"
export CIO_APP_API_KEY="Bearer <your_app_api_key>"  # different scope from Track API
export CIO_REGION="us"                              # or "eu" — region-pinned URLs

Region-pinned base URLs (CRITICAL — wrong region returns 401):

Common recipes

Recipe 1: Identify person + attributes

curl -X PUT "https://track.customer.io/api/v1/customers/$USER_ID" \
  -u "$CIO_SITE_ID:$CIO_TRACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "created_at": 1717948800,
    "plan": "pro",
    "company_id": "comp_42",
    "lifecycle_stage": "trial",
    "trial_ends_at": 1718553600
  }'

Recipe 2: Track activation event (triggers onboarding campaign)

curl -X POST "https://track.customer.io/api/v1/customers/$USER_ID/events" \
  -u "$CIO_SITE_ID:$CIO_TRACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "team_member_invited",
    "data": {
      "team_id": "team_42",
      "invitee_count": 1,
      "plan": "pro"
    }
  }'

Recipe 3: Build event-triggered onboarding campaign (App API)

curl -X POST "https://api.customer.io/v1/campaigns" \
  -H "Authorization: $CIO_APP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Onboarding — Trial",
    "type": "triggered",
    "trigger": {
      "type": "event",
      "event_name": "user_signed_up",
      "filter": {"and": [
        {"event": {"data.plan": {"eq": "trial"}}}
      ]}
    },
    "actions": [
      {"type":"email","delay_seconds":0,
       "template_id":"<welcome>","subject":"Welcome, {{customer.first_name}}"},
      {"type":"branch",
       "condition":{"customer":{"feature_first_used":{"exists":true}}},
       "true_actions":[{"type":"exit"}],
       "false_actions":[
         {"type":"email","delay_seconds":172800,
          "template_id":"<nudge1>","subject":"Need help getting started?"}
       ]}
    ],
    "exit_conditions":["plan != trial","unsubscribed"]
  }'

Recipe 4: Liquid templating with conditional content

Customer.io uses Liquid for templates. Powerful conditional logic:

<!-- email body -->
Hi {{ customer.first_name | default: "there" }},

{% if customer.plan == "trial" %}
Your trial ends in {{ customer.trial_days_left }} days.
{% elsif customer.plan == "pro" %}
You are on the Pro plan — here is your March usage:
- {{ customer.api_calls_this_month | number_with_delimiter }} API calls
- {{ customer.seats_used }}/{{ customer.seat_limit }} seats
{% endif %}

{% if customer.last_login_at < "now" | date: "%s" | minus: 604800 %}
We noticed you haven't logged in for a week.
{% endif %}

Recipe 5: Transactional message stream (separate from marketing)

Customer.io has two message-types: Transactional (no consent required, no unsubscribe, high deliverability priority) and Marketing (consented, unsubscribe required, queued).

# Send transactional via API
curl -X POST "https://api.customer.io/v1/send/email" \
  -H "Authorization: $CIO_APP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "transactional_message_id": "<tx-msg-id>",
    "to": "user@example.com",
    "identifiers": {"id":"user_42"},
    "message_data": {
      "order_id": "ord_91",
      "items": [{"sku":"abc","name":"Widget","qty":1}]
    }
  }'

Recipe 6: Broadcast — one-time to a segment

For non-recurring sends (product launch, newsletter):

curl -X POST "https://api.customer.io/v1/broadcasts" \
  -H "Authorization: $CIO_APP_API_KEY" \
  -d '{
    "name":"April product launch",
    "segment_id":"<active-workspace-owners>",
    "actions":[{"type":"email","template_id":"<launch-template>","subject":"New: AI Composer"}],
    "send_at": 1719417600
  }'

Recipe 7: Segment by behavioral cohort

curl -X POST "https://api.customer.io/v1/segments" \
  -H "Authorization: $CIO_APP_API_KEY" \
  -d '{
    "name": "Power users — last 30d",
    "type": "data-driven",
    "conditions": {
      "and": [
        {"event":{"name":"feature_used","performed":{"count":">=20","within":"30d"}}},
        {"attribute":{"plan":{"in":["pro","enterprise"]}}},
        {"event":{"name":"unsubscribed","performed":{"count":"=0"}}}
      ]
    }
  }'

Recipe 8: Smart Send Time

Customer.io's Send-time optimization analyzes per-recipient open/click history:

# Enable on campaign action
curl -X PATCH "https://api.customer.io/v1/campaigns/<id>/actions/<action-id>" \
  -H "Authorization: $CIO_APP_API_KEY" \
  -d '{"send_time_optimization": true, "fallback_send_time": "10:00", "fallback_timezone": "customer"}'

Recipe 9: Multi-workspace (B2B reseller pattern)

For agencies / multi-tenant SaaS, one Customer.io workspace per client:

# Workspace creation requires Customer.io support — list workspaces:
curl "https://api.customer.io/v1/workspaces" -H "Authorization: $CIO_APP_API_KEY"

# Per workspace, separate Site ID + Track API key. Set in env per-job.

Recipe 10: Data Pipelines — Segment-style sources

Customer.io Data Pipelines = embedded CDP. Set up Source from your product app, transformations, and Destinations (warehouse, analytics):

curl -X POST "https://cdp.customer.io/v1/sources" \
  -H "Authorization: $CIO_APP_API_KEY" \
  -d '{
    "name":"app-prod",
    "type":"http",
    "settings":{"webhookUrl":"https://cdp.customer.io/v1/p/app-prod"}
  }'

Then send events:

curl -X POST "https://cdp.customer.io/v1/p/app-prod" \
  -H "Authorization: Basic $(echo -n $CIO_WRITE_KEY: | base64)" \
  -d '{
    "userId":"user_42",
    "event":"team_member_invited",
    "properties":{"team_id":"team_42"}
  }'

Examples

Example 1: Trial-to-paid conversion sequence

Goal: for SaaS trial users, drive activation → conversion.

Steps:

  1. Identify user on signup (Recipe 1), set lifecycle_stage=trial, trial_ends_at.
  2. Track activation events as user hits milestones (Recipe 2):
  1. Build campaign with conditional branches based on which activation events fired (Recipe 3). Skip nudges if user already activated.
  2. At trial_ends_at - 3d, trigger upgrade campaign with usage stats (Recipe 4).
  3. After trial ends, branch:

Result: segmentation-aware trial sequence that skips redundant nudges and accelerates conversion.

Example 2: Stripe dunning via webhook → campaign

Goal: when Stripe says payment failed, send escalating dunning.

Steps:

  1. Stripe webhook → your backend → identify customer in Customer.io with payment_status=failed:

```bash

curl -X PUT "https://track.customer.io/api/v1/customers/$USER_ID" \

-u "$CIO_SITE_ID:$CIO_TRACK_API_KEY" \

-d '{"payment_status":"failed","last_failure_at":1717948800}'

```

  1. Track event payment_failed (Recipe 2).
  2. Campaign triggers off payment_failed event with 3-email cadence (1h, 24h, 72h).
  3. Exit condition: payment_status == "succeeded".

Edge cases

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.