How to access webhook events


(Developer Crystal) #1

Hello,

Can you please explain how to access web hook events ?

Right now we got application access token and create web hook.

Do we need to create web hook for each transfer request or only one time?

Please suggest sample code for retrieving events using web hook.

Thanks


(Stephen Ausman) #2

Hey Crystal,

Once you create a webhook subscription by making a POST request to /webhook-subscriptions (which it sounds like you already did), webhooks will be sent to the URL you specified without having to create a new subscription each time.

Our webhooks guide has some info on how to handle the webhooks on your end. If you have any questions after reading that, please let us know!


(Developer Crystal) #3

Hi,

Thank you for your quick response.

Can you please let me know how we get response on specified web hook URL?
Do we need to call Dwolla API again or just get response in POST Method?

Thanks,


(Spencer Hunter) #4

@Developer_Crystal, You’ll simply set up a webhook handler that is tasked with responding to the request from Dwolla and processing the POSTed data sent from Dwolla.


#5

First, write your website and endpoint in the app settings on the dwolla website. (It’s currently under “edit features”).

(i.e. https://www.mypage.com/coolendpoint)

Make sure that your app listens to port 80 for http or port 443 for https.

Make sure the endpoint does not result in a redirect. For example, a request on my site that looks like this:
http://mypage.com/coolEndpoint
redirects to:
https://www.mypage.com/coolEndpoint <-This one should be used for your webhook if you have a similar situation

Here is a sample code in nodejs:

//from the docs…
//this creates the web hook subscription, so that the webhooks get sent to coolEndpoint
//you can use the location to list webhooks (if you have to), among other things
var createWHSubReqBody = {
url: ‘https://www.mypage.com/coolEndpoint’,
secret: ‘best secret of all time’
};
applicationToken
.post(‘webhook-subscriptions’, createWHSubReqBody )
.then(res => res.headers.get(‘location’)); // => ‘https://api-sandbox.dwolla.com/webhook-subscriptions/5af4c10a-f6de-4ac8-840d-42cb65454216

//once the subscription is created, dwolla will send webhooks to this endpoint, via post request
//you must respond within 20 seconds with a 2XX status
//for nodejs you must also add bodyparser
//req.headers and req.body should have what you need
app.post(’/coolEndpoint’, function(req, res) {
//after processing webhook inside req
res.sendStatus(200);
});