Creating an HMAC and pushing data to a JSON Webhook connector with a secret applied

It can be a little confusing when trying to setup the JSON Webhook connector with a secret applied and push data successfully.

The biggest hurdle can often be creating the HMAC to pass in through the header. Depending on the source that you're pushing from or what programming language you're using will change the setup process and/or the libraries used. But the format of the HMAC is the same. The secret will be used as the key in the HMAC, your JSON body (data) will be the included message, and then either SHA1, SHA256 or SHA512 for the hash algorithm.

I've created an example written in Python of the process of creating an HMAC and pushing the data into Domo through the JSON Webhook connector with the secret "webhookSecret" applied to the connector.

import requests
import hashlib
import hmac

def jsonWebhookSecretExample():
    url = 'https://example.domo.com/api/iot/v1/webhook/data/aseKEdjweksKSSPwasjdflKEecklsClsjeQ'
    jsonStr = '{"data": [{"name": "Ashley", "age": 22}, {"name": "Ben", "age": 24}, {"name": "Melissa", "age": 31}, {"name": "Eddy", "age": 29}]}'
    key = 'webhookSecret'
    byteKey = bytes(key, 'UTF-8')
    message = jsonStr.encode()
    hashed = hmac.new(byteKey, message, hashlib.sha1)
    response = requests.post(url, headers={'X-Hub-Signature': hashed.hexdigest(), 'Content-Type': 'application/json'})