How to setup your first webhook?

Connecting your business to RevOps is exciting and helps unlock new opportunities for automating your billing, feature activation, and notify different teams in your business what to do after a customer signs.

We use a simple example to show how deal-activated events can be used to enable feature flags. It is a simple application but demonstrates the power webhooks.

With this guide, you will:

  1. Create a webhook endpoint.
  2. Utilize information from a Deal.
  3. Print a message out in your app.

How do RevOps Webhooks work?

On every change that occurs to a Deal in RevOps, a webhook request will be sent to the URL(s) configured in your RevOps account. This request will contain information about the event.

Webhooks under the hood

URLs for webhooks are configured in your RevOps instance inside Settings > Webhook

The following is a python example, but can be adapted to any language.

Installation requirements

  1. ngrok https://ngrok.com/download
  2. python Python >=3.6 https://www.python.org/
  3. pip https://github.com/pypa/pip

Step 1: Clone & run the example webhook server

Get started by cloning the following project from GitHub.

$> git clone https://github.com/revops-io/revops-webhook-server
$> cd revops-webhook-server
$> pip install -r requirements.txt
$> python server.py
$> ngrok http 3005

Start with server.py, which uses Flask to handle a JSON POST request.

The following snippet is an example webhook server included: https://github.com/revops-io/revops-webhook-server/blob/master/server.py

Step 2: Connect your webhook server to RevOps

You must have been assigned a developer role in RevOps to access settings.

  1. Log in to your RevOps account.
  2. Go to Settings > Webhook
  3. Create a new webhook endpoint, and set the public facing ngrok url. Example: https://5976509bfc0d.ngrok.io
  4. Click Save.
  5. Test with a specific Deal Id from your instance. See All Deals and grab your deal id from the URL.
  6. Click the Test Configuration button.

An example of a completed test! Webhooks Configuration

Step 3: Error handling

Let's extend the server.py example a bit to handle errors when communicating to your own feature flag service.

from flask import Flask, request

app = Flask(__name__)

@app.route("/deals/activated", methods=['POST'])
def deal_activated():
    """ Get flags from deal activation """
    # Create a response object from the webhook's json
    response = request.get_json()

    # Get the deal
    deal = response.get('deal', {})
    flags = deal.get('feature_flags', [])

    try:
      for flag in flags:
        name = flag.get('name')
        enabled = flag.get('enabled', False)
        if enabled == True:
          print(f"Enabling FeatureFlag {name}")
          raise Exception("A problem occurred setting a flag")
    except Exception as e:
      print('An error occurred trying to set flags')
      print(e)
      # Return 500 will tell RevOps to retry requests
      return str(e), 500

    return 'received!', 200

if __name__ == "__main__":
    app.run(debug=True, port=3005)