<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to correctly validate v2 request signature in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/521004#M48401</link>
    <description>&lt;P data-unlink="true"&gt;Incase this is helpful for anyone, I've been trying to inpliment the V2 signature validation using AWS Lambda, unfortunately AWS API Gateway does not expose the original URL and I've been trying to reconstruct it using the queryStringParameters attribute of the event object. Using &lt;A href="https://www.postman.com/" target="_blank" rel="noopener"&gt;Postman&lt;/A&gt;,&amp;nbsp;I was able to set up a mock server which I pointed the HubSpot API towards. Postman then provided me with an example URL that HubSpot made it's GET request to, I could then use this URL as a template for reconstruction.&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;One thing to note, AWS decodes the URL parameters so for a URL like&amp;nbsp;&lt;A href="https://www.google.com/search?q=HubSpot%20API," target="_blank" rel="noopener"&gt;https://www.google.com/search?q=HubSpot%20API,&lt;/A&gt;&amp;nbsp;AWS Lambda will provide the parameters like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(event["queryStringParameters"])

{"q":"HubSpot API"}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So to reconstruct the URL, you need to encode each of the URL parameters using the &lt;A href="https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_plus" target="_blank" rel="noopener"&gt;urllib.parse.quote_plus&lt;/A&gt; function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from urllib.parse import quote_plus

params = [["userId","123"],["userEmail","me@company.com"],["associatedObjectId","123456"],["associatedObjectType","DEAL"],["portalId","12345"]]

url_query = []

for p in params:
    url_query.append(p[0] + "=" + quote_plus(p[1]))

url_query = "&amp;amp;".join(url_query)

print(url_query)

userId=123&amp;amp;userEmail=me%40company.com&amp;amp;associatedObjectId=123456&amp;amp;associatedObjectType=DEAL&amp;amp;portalId=12345&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then you can join it back to the original URL:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;url = "https://www.example.com/api"
url_query = "userId=xxx&amp;amp;userEmail=xxx%40xxx.com&amp;amp;associatedObjectId=xxx&amp;amp;associatedObjectType=xxx&amp;amp;portalId=xxx"

completeURL = url + "?" + url_query&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Note that the email address will always contain an @ symbol, so the URL encoding step is always needed to convert&amp;nbsp;@ to %40.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Nov 2021 08:34:30 GMT</pubDate>
    <dc:creator>Frederick</dc:creator>
    <dc:date>2021-11-05T08:34:30Z</dc:date>
    <item>
      <title>Unable to correctly validate v2 request signature</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/290044#M26924</link>
      <description>&lt;P&gt;I'm trying to follow the steps at&amp;nbsp;&lt;A href="https://developers.hubspot.com/docs/faq/v2-request-validation" target="_blank" rel="noopener"&gt;https://developers.hubspot.com/docs/faq/v2-request-validation.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to validate the hubspot signature, but am currently unable to produce a hash consistent with what I'm seeing in the&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;X-HubSpot-Signature&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;value. I suspect this is because the URL I'm putting into the library is not exactly the correct one, but can't be sure. I.e. I suspect the problem may be similar to having a unexpected trailing slash, badly encoded query parameter or something like that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm using node.js / express, and I'm producing the hash exactly using the method from the code example from the support page. Inputting the example source strings provided does indeed produce the expected checksums.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there any way to debug this issue? E.g. being able to see the input source string that HubSpot actually uses to produce the value in&amp;nbsp;&lt;FONT face="courier new,courier"&gt;X-HubSpot-Signature&lt;/FONT&gt;?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm currently only trying to make a GET-request work, so producing the input source string should be straight-forwards. For the sake of it, here's the express code that creates the string.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import crypto from 'crypto';

function validateHubspotSignature(req, res) {
  const HubspotSignature = req.get('X-HubSpot-Signature');
  
  const stringToHash =
    process.env.HUBSPOT_CLIENT_SECRET
    + req.method
    + req.protocol + '://' + req.get('host') + req.url;

  const hash =
    crypto.createHash('sha256').update(stringToHash).digest('hex');

  // Expecting `hash` and `HubspotSignature` to match, but they do not.
};&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried using req.originalUrl etc as well. (I've of course also verified that protocal and method etc are what I expect, and even tried with different combinations, all to no luck).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Philip&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 12:11:15 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/290044#M26924</guid>
      <dc:creator>philipnilsson</dc:creator>
      <dc:date>2019-09-06T12:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to correctly validate v2 request signature</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/290211#M26949</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/104530"&gt;@philipnilsson&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope all is well with you &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mind sharing with me the request here that you're verifying the signatures for? E.g. &lt;EM&gt;Webhook Workflow&lt;/EM&gt;. This is because the concatention of the X-HubSpot-Signature header is different from the Webhooks API. As documentated here:&amp;nbsp;&lt;A href="https://knowledge.hubspot.com/articles/kcs_article/workflows/how-do-i-use-webhooks-with-hubspot-workflows#verify-request-signatures-in-workflow-webhooks" target="_self" rel="nofollow noopener noreferrer"&gt;Verify request signatures in workflow webhooks&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, could you also share with me the value for &lt;EM&gt;stringToHash&lt;/EM&gt;&amp;nbsp;before the value has been hashed so that I can take a further look into it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're more comfortable, you can share these information across via DM.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 01:56:43 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/290211#M26949</guid>
      <dc:creator>WendyGoh</dc:creator>
      <dc:date>2019-09-09T01:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to correctly validate v2 request signature</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/414017#M41009</link>
      <description>&lt;P&gt;I realize this is very late, however I recently encountered this issue and in hopes of saving someone else the time I thought I'd share.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying to validate the CRM Contact Card request which is a GET request. I was stuck for quite a while because I was passing in the exact path it was calling, as per the documentation.&lt;/P&gt;&lt;P&gt;What I expected: "&lt;A href="https://mypathhere/controllername/function" target="_blank"&gt;https://mypathhere/api/v1/myfunctionname"&lt;/A&gt;&lt;/P&gt;&lt;P&gt;What it turned out to be: "https://mypathhere/api/v1/myfunctionname?userId=???????&amp;amp;userEmail=????????&amp;amp;associatedObjectId=????&amp;amp;associatedObjectType=CONTACT&amp;amp;portalId=??????"&lt;/P&gt;&lt;P&gt;Trouble is, the CRM Contact Card appears to add extra parameters to the query that I wasn't aware of.&lt;/P&gt;&lt;P&gt;I thought they had to be set explicitly but they seem to be sent by default.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 08:42:35 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/414017#M41009</guid>
      <dc:creator>RMcKenzie</dc:creator>
      <dc:date>2021-03-02T08:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to correctly validate v2 request signature</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/521004#M48401</link>
      <description>&lt;P data-unlink="true"&gt;Incase this is helpful for anyone, I've been trying to inpliment the V2 signature validation using AWS Lambda, unfortunately AWS API Gateway does not expose the original URL and I've been trying to reconstruct it using the queryStringParameters attribute of the event object. Using &lt;A href="https://www.postman.com/" target="_blank" rel="noopener"&gt;Postman&lt;/A&gt;,&amp;nbsp;I was able to set up a mock server which I pointed the HubSpot API towards. Postman then provided me with an example URL that HubSpot made it's GET request to, I could then use this URL as a template for reconstruction.&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;One thing to note, AWS decodes the URL parameters so for a URL like&amp;nbsp;&lt;A href="https://www.google.com/search?q=HubSpot%20API," target="_blank" rel="noopener"&gt;https://www.google.com/search?q=HubSpot%20API,&lt;/A&gt;&amp;nbsp;AWS Lambda will provide the parameters like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(event["queryStringParameters"])

{"q":"HubSpot API"}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So to reconstruct the URL, you need to encode each of the URL parameters using the &lt;A href="https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_plus" target="_blank" rel="noopener"&gt;urllib.parse.quote_plus&lt;/A&gt; function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from urllib.parse import quote_plus

params = [["userId","123"],["userEmail","me@company.com"],["associatedObjectId","123456"],["associatedObjectType","DEAL"],["portalId","12345"]]

url_query = []

for p in params:
    url_query.append(p[0] + "=" + quote_plus(p[1]))

url_query = "&amp;amp;".join(url_query)

print(url_query)

userId=123&amp;amp;userEmail=me%40company.com&amp;amp;associatedObjectId=123456&amp;amp;associatedObjectType=DEAL&amp;amp;portalId=12345&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then you can join it back to the original URL:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;url = "https://www.example.com/api"
url_query = "userId=xxx&amp;amp;userEmail=xxx%40xxx.com&amp;amp;associatedObjectId=xxx&amp;amp;associatedObjectType=xxx&amp;amp;portalId=xxx"

completeURL = url + "?" + url_query&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Note that the email address will always contain an @ symbol, so the URL encoding step is always needed to convert&amp;nbsp;@ to %40.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 08:34:30 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/521004#M48401</guid>
      <dc:creator>Frederick</dc:creator>
      <dc:date>2021-11-05T08:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to correctly validate v2 request signature</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/531946#M49019</link>
      <description>&lt;P&gt;Also ran across the the same issue. I wonder if there's any way to solve without hardcoding the specifc order or params as api gateway re-organises them &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Nov 2021 03:51:05 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/531946#M49019</guid>
      <dc:creator>timtam1</dc:creator>
      <dc:date>2021-11-25T03:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to correctly validate v2 request signature</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/677592#M55645</link>
      <description>&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can inspect the request URL being sent to your API from &lt;A href="https://requestbin.com/" target="_blank" rel="noopener"&gt;https://requestbin.com,&lt;/A&gt; where you'll see all these paramters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/104530"&gt;@philipnilsson&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 00:28:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/677592#M55645</guid>
      <dc:creator>AChong1</dc:creator>
      <dc:date>2022-08-09T00:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to correctly validate v2 request signature</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/677628#M55647</link>
      <description>&lt;P&gt;HI Wendy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What does the concatenation typically look like in this case?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 02:25:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/677628#M55647</guid>
      <dc:creator>AChong1</dc:creator>
      <dc:date>2022-08-09T02:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to correctly validate v2 request signature</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/677640#M55649</link>
      <description>&lt;P&gt;yes, you can see these params in your postman mock server in the order hubspot likes them. In serverless functions, you'll need to add portal ID manually to the params since it's apparently not received by the serverless function.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 03:30:08 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Unable-to-correctly-validate-v2-request-signature/m-p/677640#M55649</guid>
      <dc:creator>AChong1</dc:creator>
      <dc:date>2022-08-09T03:30:08Z</dc:date>
    </item>
  </channel>
</rss>

