#jay_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1326342171900641310
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello! You can't do this with Python, you have to use the CLI.
You can retrieve the Events with Python though: https://docs.stripe.com/api/events/retrieve
Hi, there is a quite a large number of failed events, so it is quite difficult to using the CLI
Is there a work around this?
You could use Python to script calls to the CLI.
Could you help me guide on how to use Python to script calls to the CLI?
Is there a place where I can reference python to script calls to the CLI?
I can't help you with that, no. Seems like this may be helpful though: https://stackoverflow.com/questions/89228/how-do-i-execute-a-program-or-call-a-system-command
I see, just to double-check with you there is no related documentation on Stripe's side nor a developer that could help me implement this right?
No, this is something you would need to do on your end.
Understood. Thank you!
Do you ever intend to migrate the stripe CLI above to be supported in python or other languages in the future?
I don't believe there are any plans to, no. Stripe CLI is intended to be a developer tool, not something you would use routinely in production.
I see, thank you so much Rubeus!
Happy to help!
Last thing, we had constant failures for certain webhook event types since mid-December. There were too many cases that we were not able to re-send the webhooks manually. Now that I have fixed the root cause of the webhook failures, I want to re-run all these so there logic is applied.
Do you think what I am doing makes sense?
- get list of all failed events
- resend them chrnologically using Stripe CLI
Or does Stripe has other recommended steps to take for such situations that I am in?
Usually we recommend fetching the Events from the API and processing them directly, not resending them to your Webhook Endpoint.
As a simplified example, if your webhook handling code has something like a process_webhook(event) function, write a script that fetches the Events from the API and calls process_webhook(event) for each one instead of resending.
on our backend, we implemented an endpoint that handles stripe webhooks for each event types.
So based on what you described, do you think it would be better to define the function process_webhook(event) to call the stripe webhook handling API endpoint directly instead of using the CLI to resend events -> which leads to eventually hitting the stripe webhook handling API endpoint on our BE?
No, that was just a simplified example.
I'm saying that you already have code running to process Events. It runs when an Event is delivered to your webhook URL. Why can't you run the same code after fetching an Event from the API?
Like why do you need to have the Event sent by us to your webhook URL? Why can't you fetch the Event from the API and trigger the same code without involving your webhook URL or resending Events?
Does that make sense?
Yeah that makes a lot of sense, let me have a look at reach out again here if I come across any more questions. Thank you for the help!
No problem!
Hey Rubeus,
I gave it a little more thought
We fetch the failed list of failed events by delivery_success = false on the stripe.Event.List API
The idea was that whenever we ran this script, we would:
- get all failed webhooks
- resolve all failed webhooks
such that if we call this script again right away, we get 0 results since the failed webhooks would have been flagged as "success" after re-sending the CLI
Calling the process_webhook function (or the equivalent) directly would mean that the events will still be marked as "failed" , so the next time we run the script, the same sets of events will be fetched.
I believe that there is no way to "update" the event through Stripe API neither. Are my assumptions correct?
That's correct. The recommended approach would be to keep track of the Event IDs you've already processed successfully and ignore those if you run the script again.
By keeping track, do you mean store the event IDs in a database on our side and filter them out in the next script run against our database?
Yep!