Stripe CLI: How to resend events with nested metadata
Asked Answered
D

1

6

I'm using Stripe CLI to resend local webhook events. The command lets me set metadata using the following option / syntax: https://stripe.com/docs/cli/events/resend#events_resend-param

-d nested[param]=value

However the following attempts all result in a Received unknown parameter error.

stripe events resend event_id -d metadata[customer_id]=5678
stripe events resend event_id -d object[metadata][customer_id]=5678
stripe events resend event_id -d data[object][metadata][customer_id]=5678
stripe events resend event_id -d [data][object][metadata][customer_id]=5678

Anyone know how to successfully add nested params through the Stripe CLI?

Doubletime answered 4/8, 2022 at 14:58 Comment(0)
I
1

The -d nested[param]=value parameter is supposed to be used to specify the api endpoint's parameters. For example:

Suppose you're using the 'events list' endpoint (https://docs.stripe.com/api/events/list). It has the created parameter, which you can use to specify you want to filter events by their creation date. Suppose you want to get all events created after 2024-06-13. For this, you'd do:

stripe events list --data "created[gte]=$(date --date='2024-06-13' +%s)"

Notes:

  • --data is the same as -d
  • gte stands for 'greater or equal'
  • $(date --date='2024-06-13' +%s) will resolve to 1718247600, which is the Unix Epoch = seconds since 1970-01-01 00:00 UTC.

Another parameter of events list endpoint is delivery_success, which can be either true or false. If you want to use it, you can specify --data (or -d) multiple times:

stripe events list --data "created[gte]=$(date --date='2024-06-13' +%s)" --data="delivery_success=false"

Stripe CLI has the --created but it is [fixed][1] to the eq child parameter (there's no way to specify gte, for example). Using --data makes it easier.

Note that for the resend command to work, you'll need the Webhook Endpoints Write permission enabled in your API key.

[1] You can check this by entering an invalid number for --created, such as:

stripe events list --created=NaN

See the response:

{
  "error": {
    "code": "parameter_invalid_integer",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-invalid-integer",
    "message": "Invalid integer: NaN",
    "param": "created[eq]",
    "request_log_url": "https://dashboard.stripe.com/logs/req_*******?t=*******",
    "type": "invalid_request_error"
  }
}
Ivanivana answered 26/6, 2024 at 20:8 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.