stripe-cli icon indicating copy to clipboard operation
stripe-cli copied to clipboard

Unexpected behavior with `--load-from-webhooks-api`

Open duien opened this issue 5 years ago • 5 comments

The more information we have the easier it is for us to help. Feel free to remove any sections that might not apply

Issue

I'm trying to test webhook behavior locally after creating a webhook that's locked to a specific API version. I'm replacing an existing webhook, so I created the new one with its version configured, then disabled the old one. The configuration, as reported by stripe webhook_endpoints list is:

{
  "object": "list",
  "data": [
    {
      "id": "we_1G1yutE4uzkYsaGZBVIN79Uf",
      "object": "webhook_endpoint",
      "api_version": "2015-09-08",
      "application": null,
      "created": 1579283251,
      "enabled_events": [
        "customer.subscription.deleted",
        "invoice.payment_succeeded",
        "invoice.payment_failed"
      ],
      "livemode": false,
      "status": "enabled",
      "url": "https://stripe:[email protected]/integrations/stripe/webhook"
    },
    {
      "id": "we_189qe8E4uzkYsaGZMlfFmSyv",
      "object": "webhook_endpoint",
      "api_version": null,
      "application": null,
      "created": 1462947396,
      "enabled_events": [
        "*"
      ],
      "livemode": false,
      "status": "disabled",
      "url": "https://stripe:[email protected]/integrations/stripe/webhook"
    }
  ],
  "has_more": false,
  "url": "/v1/webhook_endpoints"
}

As you can see, I have an enabled webhook with api_version and a specific list of events, and a disabled webhook with no version or events specified.

When I listen with the command stripe listen --forward-to localhost:3000 --load-from-webhooks-api I am getting the events that would be sent to both webhooks, including the disabled one, and all events that I'm receiving for either hook are using the account's default API version rather than the one configured. Looking at the matching event sent to the actual hook, it is using the configured version as expected.

Expected Behavior

When using --load-from-webhooks-api I expected the local listener to receive the same events in the same format as what's being sent to the actual hook. In this case, I expected to receive only the 3 event-types that my enabled hook is configured for, and I expected the data I receive to use the api version configured for that hook.

Steps to reproduce

  1. Create a disabled webhook and a webhook with a specific API version set (different from account-wide configuration). For easiest testing, configure them with two different sets of events.
  2. Run Stripe CLI with --load-from-webhooks-api
  3. Trigger an event
  4. See that events are posted to the local webhook include events for the disabled webhook, and that the api_version in the posted data always corresponds to the account-wide version.

Environment

macOS

duien avatar Jan 17 '20 20:01 duien

Hey @duien! This is a current limitation with the CLI and the infra. It's pretty much the same issue as #342, it's not currently possible for the CLI to pick API versions that are passed through.

I don't have a timeline for a fix but I'll surface this with the team internally and see if we can get something on the roadmap.

tomer-stripe avatar Jan 17 '20 21:01 tomer-stripe

Thanks for the response! That totally makes sense. It does seem like forwarding based on disabled hooks is a separate issue, and one that might be a little simpler, but also something that's not likely to come up all that often.

For both issues, I think a mention of the limitations in the docs for --load-from-webhooks-api would be a big help -- I spent a lot of time trying to track down why my webhook wasn't behaving as expected, and having the additional noise from the disabled webhook made it trickier to figure out what was going on.

Overall, though, the CLI has been extraordinarily useful, and I really appreciate the thought and care that the team clearly put into the developer experience.

duien avatar Jan 17 '20 23:01 duien

Adding it to the docs is definitely a good idea and a lapse on my part 😅. I'm traveling this week but will try to get that added!

I also talked to one of my teammates last week about this and we're seeing what we can do solve this. No updates yet but I'll keep this open to share any news here.

tomer-stripe avatar Jan 22 '20 01:01 tomer-stripe

Hi, Still no news ? Or another way to force the api_version into the test event locally? Thx

giulianf avatar May 10 '21 09:05 giulianf

+1 for fixing a way to specify the API version when using stripe listen

Lewenhaupt avatar May 19 '21 10:05 Lewenhaupt