Code

Heroku makes it easy to post a webhook when you deploy an app using the HTTP Deploy Hooks add-on but there’s no way to post the webhook to more than one URL. This is a problem if you want to notify a few different services of the deploy, like an exception tracker and NewRelic. Of course you could spin up a new app just to catch the webhook and resend it, but that’s a lot of nonsense for something that should be simple.

The other alternative is to use Torpio, which makes it dead-simple to catch the webhook and resend wherever you like. It’s a great service for building lightweight connectors between services with some nice features:

  • scripts are written in CoffeeScript 🙂
  • your scripts have access to simple HTTP and logging functions
  • scripts can be triggered via a webhook or email
  • it’s free for a reasonable number of scripts & executions

Let’s walk through how to use Torpio to setup a script that will catch the deploy webhook from Heroku and resend it to a few services.

Heroku Deploy Hooks Using Torpio

First, sign in and create a new script. Scroll down to the bottom and you’ll see the webhook URL. Copy this and then log into your Heroku account and go to the deploy hooks add-on. Enter the webhook URL and hit save.

Copy in this code for your script:

This script does a few things. First, you can enter multiple URLs that accept Heroku’s deploy hook without any changes. The format is a simple application/x-www-form-urlencoded POST with few parameters. The most important are app, user, and head. You can see the rest in the HTTP deploy hook docs. Because Torpio passes in the webhook body without modification, we can simple repost this to the URLs that we need. Most developer-related services will accept Heroku’s webhook format without any changes.

For services that don’t accept Heroku’s webhook format (NewRelic, for example), we can craft our own body and POST it. Since we want to be able to use this same script for multiple apps, the script does a bit of translation from the Heroku app slug to the NewRelic app ID. We can then use the same webhook URL and script for every app.

That’s it! This is a very simple example of the sort of thing you can do with Torpio. They have some great examples in their getting started guide and excellent developer docs. If you need to integrate one of their supported services, you even get built-in authentication management which is a really awesome feature and a huge time-saver.

Go forth and integrate!

Published by Max Rice

Max is one of our co-founders, CEO, resident webhook expert, and coffeescript lover. He's a top WooCommerce contributor, unit test aficionado, survivor of coding with timezones, and spends much of his time being the chief bottleneck at SkyVerge.

2 Comments

  1. Hi there,

    I think that it is possible to define more than one webhook so there is no need to catch a single notification using a special application and than propagate it between other services.

    However I totally agree that defining webhooks using Heroku CLI is not comfortable. On Shelly Cloud we allow user to add a custom script with the commands to invoke after successfully deployment (https://shellycloud.com/documentation/deployment_hooks#after_successful_deploy_hook). Sometimes there is a need to do something right before running the migrations or before restarting the services (such as application webserver) so we have also support for this kind of hooks.

    • hey thanks for the comment! I’m not aware of any way to have multiple HTTP deploy hooks on Heroku, though I’ve not looked at their docs in a few months so that could’ve changed 🙂

      Shelly Cloud looks pretty cool btw!

Hmm, looks like this article is quite old! Its content may be outdated, so comments are now closed.