Hello !
I’m trying to follow the documentation to validate the v3 request signature for webhooks using Python
But i can’t manage to match the v3 signature provided in the request header with the signature that I compute on my side.
For my test, I used a sandbox environment with a private app that I set up. Then i created a webhook subscription using Hubspot UI ( in the webhook section of my private app), and triggered a test request in the details of my webhook subscription.
import hmac
from base64 import b64encode
from hashlib import sha256
import json
# Request data
header_signature = "..."
header_timestamp = "1732715701368"
request_payload = [
{
"appId": 4708013,
"eventId": 100,
"subscriptionId": 2963051,
"portalId": 145106154,
"occurredAt": 1732715551737,
"subscriptionType": "deal.deletion",
"attemptNumber": 0,
"objectId": 123,
"changeSource": "CRM",
"changeFlag": "DELETED"
}
]
# Private app data
webhook_url = "https://my.domain.com/webhook-path"
secret_key = "xxxxxxx-xxxx-xxxx-xxxxxxxxxxx"
msg = "POST" + webhook_url + json.dumps(request_payload) + header_timestamp
print(string)
# POSThttps://my.domain.com/webhook-path[{"appId": 4708013, "eventId": 100, "subscriptionId": 2963051, "portalId": 145106154, "occurredAt": 1732715551737, "subscriptionType": "deal.deletion", "attemptNumber": 0, "objectId": 123, "changeSource": "CRM", "changeFlag": "DELETED"}]1732715701368
computed_signature = b64encode(hmac.new(secret_key.encode("utf-8"), msg=msg.encode("utf-8"), digestmod=sha256).digest()).decode("utf-8")
print(computed_signature == header_signature)
# False
But my computed signature doesn’t match with the header signature.
I made sure to use the app’s private key, and the webhook url doesn’t have any URL-encoded characters.
Does anyone have managed to make it work using Python ?
Or can help me solve this issue ?
Big thanks !