How to locally test your webhooks (even if your local application runs in a container)

Sometimes we need to add endpoints to allow other applications to send us webhooks. Some applications, such as Stripe, provide their own command-line interface (CLI) that helps us integrate their webhooks and develop locally. But there are other applications, like HubSpot (which is the one we’ll use in this guide), that don’t give us those types of tools. In those cases, some other tools can help us to develop and test webhooks locally. The tool we’ll be using in this (very) short guide is webhook.site.

To begin, let’s get the webhooksite/cli container, and for that we just need to run the following:

docker run -ti webhooksite/cli sh

After running this command, Docker will automatically add the webhooksite/cli image, start the container, and give us a prompt so we can interact with it.
To make sure everything is working correctly, you can run whcli help. If it works correctly, you’ll see a screen like this:

Now we’re sure we’ve the webhook.site container up, and it’s working, we just need to start connecting to it.

The first thing we’ll do is create a new endpoint. As I’m working with HubSpot, I’ve created a new endpoint under /webhooks/hubspot.

Once the endpoint is created, you’ll need to go to https://webook.site/ and copy the URL under “Your unique URL”, and paste it in the application we want to connect.

If you’re connecting to HubSpot as I’m you’ll need to go to your account > Settings > Integrations > Private Apps, then create a new private app or open the existing private app you’ve previously created to allow connections to your account, and go to the Webooks tab. Then, paste the URL you’ve copied from webhook.site on the URL field.

Save your changes, and we’re ready to continue.

Now that we’ve connected the third-party application with webhook.site, we just need to start our local connection with webhook.site, for that, let’s copy the command from here:

And before pasting and running it, we’ll make some modifications to the target parameter. We’ll need to write the full path to the endpoint we’ve created, so if your path is, for example, /api/webhooks/test your target will be https://localhost/api/webhooks/test.
Important note: if your local application is running in docker, you must replace localhost with host.docker.internal, so the final target URL will look like this http://host.docker.internal/api/webhooks/test.

Then, you can finally execute the full command that will look something like
whcli forward --token={your_token} --target=http://host.docker.internal/api/webhooks/test

And after that, your local application is successfully connected to any third-party application’s webhooks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.