Webhook Format and HMAC Information

Format

📘

Important Fields

If you wish to consume exactly the same responses as you get from the API, look under _rest key. If you also want to see who the object was updated by and what function was used to perform the update, look under the webhook_meta key which is added to the webhook on creation.

KeyTypeDescription
_id.$oidstringObject ID of webhook
client_idstringObject ID of client
dateintegerDate webhook was created (milliseconds since Unix epoch time).
functionstringResource | Method
http_response_codestringResponse code from webhook URL
http_response_textstringResponse text from webhook URL
http_responses[]array of objectsList of response data from webhook URL. See Webhook URL Response Object (below) for more information
http_urlstringURL webhook was sent to
object_idstringObject ID attached to resource type
safe_obj._id.$oidstringObject ID of resource
safe_obj._restobjectContains information about the resource (node, transaction, and user objects)
safe_obj.webhook_metaobjectContains information about webhook subscription updates (e.g. who the object was updated by, function used to perform the update, etc.)
safe_obj.webhook_meta.functionstringThe function assoicated with the webhook (e.g. "NODE|PATCH").
safe_obj.webhook_meta.log_idstringThe ID of the log associated with the webhook.
safe_obj.webhook_meta.updated_bystringWho updated the webhook subscription (e.g. "SELF", "BACKEND", etc.).
safe_obj.webhook_meta.date.$dateinteger (milliseconds since Unix epoch time)The webhook creation date.
safe_obj_hashstringHashed object information
updated_bystringFor internal use

Webhook URL Response Object

KeyTypeDescription
date integerDate webhook received a response from webhook URL
http_response_codestringResponse code from webhook URL
http_response_textstringResponse text from webhook URL
http_urlstringURL webhook was sent to

HMAC for Webhooks

Every webhook will be signed with HMAC.

HMAC is a protocol that helps you judge the authenticity of the received message. This comes in handy when you want to quickly find out whether the webhook was sent by Synapse or a malicious/notorious party.

The signature is a SHA-1 and SHA-256 HMAC hash of the object_id + your client_id, with the secret key as your client_secret.

  • Please note that Python (FullBody) listed below uses the entire body of a webhook to create a signature, which can used to rebuild a X-Synapse-Signature-SHA256-FullBody signature.

You will be able to rebuild the signature the following way:

import hmac 
from hashlib import sha1, sha256

key = 'your_client_secret'
raw = '{0}+{1}'.format(payload['_id']['$oid'],'your_client_id')

hashed_sha1 = hmac.new(key, raw, sha1)
hashed_sha256 = hmac.new(key, raw, sha256)

# The signature
print hashed_sha1.hexdigest()
print hashed_sha256.hexdigest()
import hmac 
from hashlib import sha1, sha256

webhook = '''the webhook json'''

key = bytes('your_client_secret','utf-8')
raw = bytes(webhook,'utf-8')

hashed_sha256 = hmac.new(key, raw, sha256)

# The signature
print(hashed_sha256.hexdigest())

Please note that raw should look like this (with +):
563db3fb86c27307d925871f+e3f19e4bd4022c86e7f2

Not like this (without +):
563db3fb86c27307d925871fe3f19e4bd4022c86e7f2.

Since the sha1 signature is in hex, it should look like this:

  • 5bce964c20b0c36313d8f7cffc2ff4772d0c96750

We then take this signature and add it into the header of the request with name X-Synapse-Signature and X-Synapse-Signature-Sha256.

Additional Information

  • Platforms should only send notifications to users if a specific field in the webhook changes. For example, if the status of the transaction changes, you should send an email to your users, but if a new field is added to the webhook response, that should not automatically trigger an email because it does not affect the user