I’m having an issue trying to validate a webhooks request to my application. I’m following the instructions here: Accounts Dashboard | HubSpot but I can’t seem to generate a matching hash.
No luck there. The request body is already in the format needed for the sha256 hashing algorithm to run on it, so trying to cast it to a string just causes that to fail.
Casting it to a string and then encoding it back into ASCII gives the same result as just leaving it as is.
So the odd thing is that I’m having trouble validating the signature for test webhook notificaitons, but I’m succeeding for live webhook notifications by copy/pasting my client secret & request body using the following code:
import hashlib
client_secret = # Client secret here, pasted as a string
body = # Request body here, pasted as a string
source_string = client_secret + body
finalHash = hashlib.sha256(source_string).hexdigest()
print(finalHash)
Are the issues you’re seeing with live webhook notifications? The reason I’m thinking that it may be an encoding/stringification issue of some kind is because I haven’t been able to reproduce the issues myself.
I’m not particularly familiar with Django; is it possible that request.body isn’t encoded correctly? The following stackoverflow article seems to imply it’s a byte string:
Makes sense, thanks for sharing! As an update, I just heard from the team this morning that the issue with test webhooks has been resolved, so going forward all webhook-related signatures should function correctly.