Workflows / Stripe / customer.subscription.deleted

Stripe customer.subscription.deleted Event Notification to Slack & Email

Learn how to listen to the customer.subscription.deleted webhook event from Stripe to trigger a notification workflow in MagicBell.

Event payload

Sample payload for the customer.subscription.deleted event.

{
  "api_version": "2023-10-16",
  "created": 1694109261,
  "data": {
    "object": {
      "cancel_at": 1694109261,
      "canceled_at": 1694109200,
      "cancellation_details": {
        "comment": null,
        "feedback": "too_expensive",
        "reason": "cancellation_requested"
      },
      "created": 1679609767,
      "currency": "usd",
      "current_period_end": 1682288167,
      "current_period_start": 1679609767,
      "customer": "cus_Na6dX7aXxi11N4",
      "ended_at": 1694109261,
      "id": "sub_1MowQVLkdIwHu7ixeRlqHVzs",
      "items": {
        "data": [
          {
            "id": "si_Na6dzxczY5fwHx",
            "object": "subscription_item",
            "price": {
              "currency": "usd",
              "id": "price_1MowQULkdIwHu7ixraBm864M",
              "object": "price",
              "product": "prod_Na6dGcTsmU0I4R",
              "recurring": {
                "interval": "month",
                "interval_count": 1
              },
              "unit_amount": 1000
            },
            "quantity": 1,
            "subscription": "sub_1MowQVLkdIwHu7ixeRlqHVzs"
          }
        ],
        "object": "list"
      },
      "livemode": false,
      "object": "subscription",
      "start_date": 1679609767,
      "status": "canceled"
    }
  },
  "id": "evt_1NqIdSLkdIwHu7ixNnX0Yz3a",
  "livemode": false,
  "object": "event",
  "type": "customer.subscription.deleted"
}

Connect Stripe to MagicBell to receive events and trigger workflows. This guide uses the MagicBell CLI.

Add the Stripe integration

Save your Stripe webhook signing secret in MagicBell. See Stripe webhooks.

magicbell integration save_stripe \
  --data '{"webhook_signing_secret":"whsec_xxx"}'

Copy the ID from the response and use it to build your webhook URL:

https://api.magicbell.com/v2/integrations/stripe/webhooks/incoming/{id}

Setup the webhook

Add a workflow

Create a workflow that triggers automatically when Stripe sends this event. Use liquid templates to access fields in your workflow.

Workflow key

Use this key to trigger the workflow when Stripe sends a customer.subscription.deleted:

integration.stripe.customer.subscription.deleted

Example workflow

Confirm cancellation to customer and notify the customer success team for potential win-back.

{
  "key": "integration.stripe.customer.subscription.deleted",
  "steps": [
    {
      "command": "broadcast",
      "input": {
        "content": "Your subscription has been canceled. We're sorry to see you go. You can resubscribe anytime to regain access.",
        "recipients": [
          {
            "external_id": "{{payload.data.object.customer}}"
          }
        ],
        "title": "Subscription canceled"
      }
    },
    {
      "command": "broadcast",
      "input": {
        "content": "Customer {{payload.data.object.customer}} canceled their subscription. Feedback: {{payload.data.object.cancellation_details.feedback}}",
        "overrides": {
          "providers": {
            "slack": {}
          }
        },
        "recipients": [
          {
            "external_id": "customer-success"
          }
        ],
        "title": "Subscription churned"
      }
    }
  ]
}

Save with the CLI

Use the MagicBell CLI to save this workflow to your project. You can also use the Workflows API endpoint instead.

magicbell workflow save \
  --data '{"key":"integration.stripe.customer.subscription.deleted","steps":[{"command":"broadcast","input":{"content":"Your subscription has been canceled. We're sorry to see you go. You can resubscribe anytime to regain access.","recipients":[{"external_id":"{{payload.data.object.customer}}"}],"title":"Subscription canceled"}},{"command":"broadcast","input":{"content":"Customer {{payload.data.object.customer}} canceled their subscription. Feedback: {{payload.data.object.cancellation_details.feedback}}","overrides":{"providers":{"slack":{}}},"recipients":[{"external_id":"customer-success"}],"title":"Subscription churned"}}]}'

Test the workflow

Use the Stripe CLI to trigger test events and verify your workflow executes correctly.

1. Trigger a test event

Use the Stripe CLI to send a test event:

stripe trigger customer.subscription.deleted

2. Verify the workflow ran

Check that MagicBell received the event and executed the workflow:

magicbell workflow list_runs --workflow_key integration.stripe.customer.subscription.deleted

3. Debug issues

If the workflow failed or you need more details, fetch the run to see step-by-step execution:

magicbell workflow fetch_run --run_id {run_id}

Other customer notification workflows

View all Stripe workflows →