HubSpot / sample-apps-webhooks

Sample code and reference for processing HubSpot webhooks
Apache License 2.0
17 stars 9 forks source link

Ruby Encoding::UndefinedConversionError ("\xC3" from ASCII-8BIT to UTF-8) #6

Open fjvalles opened 2 years ago

fjvalles commented 2 years ago

Hi, I created a workflow with a webhook request for a private app. The webhook triggers when the firstname, lastname, email or phone is changed in a contact. It then send a request to a RoR app.

I'm using the code in this sample app. The problem is that when I try to validate the signature, I'm getting the error: Encoding::UndefinedConversionError ("\xC3" from ASCII-8BIT to UTF-8)

I traced the error to this line in Hubspot::Helpers::WebhooksHelper: hash_result = Digest::SHA2.hexdigest(source_string.encode('utf-8'))

I managed to remove the error by passing the request_body variable to the validate_signature method like this: request.raw_post.force_encoding("UTF-8")

The issue is that by doing this, the validate_signature method raises an InvalidSignatureError

I need some help to figure out how to validate the request with this encoding error please

Thanks

fjvalles commented 2 years ago

I managed to solve it by changing: http_uri: @request.base_url to http_uri: @request.url