How to call stripe.events.retrieve for Stripe Connect Webhooks?

694 views
Skip to first unread message

Yoni Rabinovitch

unread,
Apr 14, 2016, 10:32:15 AM4/14/16
to Stripe API Discussion
I am using Stripe Connect and have defined Connect Webhooks in my platform Stripe account.

In my node.js server when I receive the webhook, I call stripe.events.retrieve() with the id received in the Webhook's event_json to verify that the Webhook was indeed generated by Stripe for a legitimate event.

For some reason I am getting back
Error Type: StripeInvalidRequest. Message: No such event: evt_17ztDTFFH5u58o7XXXXXXXXX

Here is my code:

stripe.events.retrieve(
                event_json.id,
                function(err, event) {
                    if (err) {
                        winston.error('Failed to retrieve Stripe Event for Webhook: ' + JSON.stringify(event_json) + '. Error Type: ' + err.type + '. Message: ' + err.message);
                        return null;
                    }
                    return(event);
                }
            );

I also tried calling stripe.events.receive with a { stripe_account: event_json.user_id } parameter after event_json.id. In this case it looks like the stripe.events.retrieve callback never gets called.

What am I doing wrong?

Remi J.

unread,
Apr 14, 2016, 10:36:57 AM4/14/16
to api-d...@lists.stripe.com
Hey Yoni,

The issue here is that the event is not in your platform account but in the connected account itself. When you try to retrieve the event you need to explicitly tell us which account you are making the request for. This is done using the `Stripe-Account` header [1] feature and applies to any API requests you'd make on behalf of a connected account.

In Node.js, your code would be:

stripe.events.retrieve(
                event_json.id,
                {stripe_account: "acct_XXX" },
                function(err, event) {
                    if (err) {
                        winston.error('Failed to retrieve Stripe Event for Webhook: ' + JSON.stringify(event_json) + '. Error Type: ' + err.type + '. Message: ' + err.message);
                        return null;
                    }
                    return(event);
                }
            );

--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Reply all
Reply to author
Forward
0 new messages