DEV Community

zwx00
zwx00

Posted on

1

Replay failed stripe events via webhook

Sometimes webhook events fail to deliver, and you need to replay them to ensure your system processes all important events. Here's a handy one-liner using the Stripe CLI to resend failed subscription cancellation events:

stripe events list \
  --type=customer.subscription.deleted \
  --delivery-success=false \
  --live \
  --limit 150 \
  | jq ".data[].id" \
  | xargs -n1 -t stripe events resend \
    --live \
    --webhook-endpoint=we_LALALALA
Enter fullscreen mode Exit fullscreen mode

Let's break down what this command does:

  1. stripe events list: Lists Stripe events

    • --type=customer.subscription.deleted: Filters for subscription cancellation events
    • --delivery-success=false: Only shows failed deliveries
    • --live: Uses live mode (not test mode)
    • --limit 150: Retrieves up to 150 events
  2. jq ".data[].id": Extracts just the event IDs from the JSON response

  3. xargs -n1 -t: Processes each event ID one at a time

    • -n1: Passes one argument per command
    • -t: Prints each command before executing it
  4. stripe events resend: Resends each event to your webhook endpoint

    • --live: Uses live mode
    • --webhook-endpoint=we_LALALALA: Specifies the webhook endpoint to use

Remember to replace we_LALALALA with your actual webhook endpoint ID.

This command is particularly useful when:

  • Your webhook endpoint was down
  • You had network issues
  • You're testing new webhook handling code
  • You need to backfill missed events

Make sure you have both the Stripe CLI and jq installed before running this command.

Happy webhooking! 🎣

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay