<?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 Correctly parsing webhook requests for both endpoints for both Hubspot and Stripe APIs in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Correctly-parsing-webhook-requests-for-both-endpoints-for-both/m-p/701049#M57484</link>
    <description>&lt;P&gt;I am building an app on the marketplace in which I receive webhooks from the app and then make api calls to perform certain actions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the Hubspot API for most functions and the Stripe API to collect payment and verify payment status. The entire code is written in Node JS and I am running the &lt;STRONG&gt;express node js library&lt;/STRONG&gt; to listen to endpoints and deal with requests.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the setup of my express&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;const express = require('express') &lt;BR /&gt;const app = express() &lt;BR /&gt;&lt;BR /&gt;app.use(express.raw({type: "application/json"}) &lt;BR /&gt;app.use(express.json())&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using express.raw because of the stripe API which requires the raw request to be called into some kind of Buffer. Now this is the call for an example endpoint for a non-Stripe call, such as getting account settings for Hubspot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;app.post('/account-fetch', (req, res) =&amp;gt; { &lt;BR /&gt;   const portalId = req.body.portalId &lt;BR /&gt;   console.log(portalId) &lt;BR /&gt;   setup.retrieveKey(portalId, "hubname") &lt;BR /&gt;     .then((acc) =&amp;gt; { &lt;BR /&gt;        console.log(acc) &lt;BR /&gt;        const component = { &lt;BR /&gt;           "response": { &lt;BR /&gt;               "accounts": [{ &lt;BR /&gt;                    "accountId": '"' + portalId + '"', &lt;BR /&gt;                    "accountName": acc }] &lt;BR /&gt;                } } &lt;BR /&gt;         console.log(component) &lt;BR /&gt;         res.status(200).send(component) }) &lt;BR /&gt;     .catch((err) =&amp;gt; { &lt;BR /&gt;        console.error(err) &lt;BR /&gt;        res.status(400).send(err) &lt;BR /&gt;      }) &lt;BR /&gt;  }) &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the issue is that while stripe needs it to have that&lt;STRONG&gt; express.raw&lt;/STRONG&gt; call, it messes up everything else, because the Buffer is encoded and it just comes out as numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also tried on the stripe endpoint:&lt;/P&gt;&lt;PRE&gt;app.post('/stripe/:type', express.raw({type: "application/json }),(req, res) =&amp;gt; { &lt;BR /&gt;  //rest of my code &lt;BR /&gt;}) &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or not calling it at all, still no cigar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All I get is a&lt;STRONG&gt; StripeSignatureVerificationError&lt;/STRONG&gt; because it can't read the signature on the payload properly. I've tried placing that line just before the stripe endpoint, but it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to either to convert the Buffer back into what it would be if I didn't do the express.raw call or a way to just make that call isolated for one endpoint?&lt;/P&gt;</description>
    <pubDate>Sun, 02 Oct 2022 12:35:37 GMT</pubDate>
    <dc:creator>IamYIZ</dc:creator>
    <dc:date>2022-10-02T12:35:37Z</dc:date>
    <item>
      <title>Correctly parsing webhook requests for both endpoints for both Hubspot and Stripe APIs</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Correctly-parsing-webhook-requests-for-both-endpoints-for-both/m-p/701049#M57484</link>
      <description>&lt;P&gt;I am building an app on the marketplace in which I receive webhooks from the app and then make api calls to perform certain actions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the Hubspot API for most functions and the Stripe API to collect payment and verify payment status. The entire code is written in Node JS and I am running the &lt;STRONG&gt;express node js library&lt;/STRONG&gt; to listen to endpoints and deal with requests.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the setup of my express&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;const express = require('express') &lt;BR /&gt;const app = express() &lt;BR /&gt;&lt;BR /&gt;app.use(express.raw({type: "application/json"}) &lt;BR /&gt;app.use(express.json())&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using express.raw because of the stripe API which requires the raw request to be called into some kind of Buffer. Now this is the call for an example endpoint for a non-Stripe call, such as getting account settings for Hubspot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;app.post('/account-fetch', (req, res) =&amp;gt; { &lt;BR /&gt;   const portalId = req.body.portalId &lt;BR /&gt;   console.log(portalId) &lt;BR /&gt;   setup.retrieveKey(portalId, "hubname") &lt;BR /&gt;     .then((acc) =&amp;gt; { &lt;BR /&gt;        console.log(acc) &lt;BR /&gt;        const component = { &lt;BR /&gt;           "response": { &lt;BR /&gt;               "accounts": [{ &lt;BR /&gt;                    "accountId": '"' + portalId + '"', &lt;BR /&gt;                    "accountName": acc }] &lt;BR /&gt;                } } &lt;BR /&gt;         console.log(component) &lt;BR /&gt;         res.status(200).send(component) }) &lt;BR /&gt;     .catch((err) =&amp;gt; { &lt;BR /&gt;        console.error(err) &lt;BR /&gt;        res.status(400).send(err) &lt;BR /&gt;      }) &lt;BR /&gt;  }) &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the issue is that while stripe needs it to have that&lt;STRONG&gt; express.raw&lt;/STRONG&gt; call, it messes up everything else, because the Buffer is encoded and it just comes out as numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also tried on the stripe endpoint:&lt;/P&gt;&lt;PRE&gt;app.post('/stripe/:type', express.raw({type: "application/json }),(req, res) =&amp;gt; { &lt;BR /&gt;  //rest of my code &lt;BR /&gt;}) &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or not calling it at all, still no cigar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All I get is a&lt;STRONG&gt; StripeSignatureVerificationError&lt;/STRONG&gt; because it can't read the signature on the payload properly. I've tried placing that line just before the stripe endpoint, but it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to either to convert the Buffer back into what it would be if I didn't do the express.raw call or a way to just make that call isolated for one endpoint?&lt;/P&gt;</description>
      <pubDate>Sun, 02 Oct 2022 12:35:37 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Correctly-parsing-webhook-requests-for-both-endpoints-for-both/m-p/701049#M57484</guid>
      <dc:creator>IamYIZ</dc:creator>
      <dc:date>2022-10-02T12:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Correctly parsing webhook requests for both endpoints for both Hubspot and Stripe APIs</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Correctly-parsing-webhook-requests-for-both-endpoints-for-both/m-p/701268#M57500</link>
      <description>&lt;P&gt;I solved it in the end.&amp;nbsp;I used&amp;nbsp;&lt;STRONG&gt;Routers&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my end code was:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const express = require('express')
const app = express()
const stripeApp = express.Router()

stripeApp.use(express.raw({type:"*/*"}))

app.use('/stripe',stripeApp)
app.use(express.json())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and my end point was configured like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;stripeApp.post('/:type', express.raw({type: "application/json"}),(req, res) =&amp;gt; {
//my request handling code here
})&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 03 Oct 2022 12:01:16 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Correctly-parsing-webhook-requests-for-both-endpoints-for-both/m-p/701268#M57500</guid>
      <dc:creator>IamYIZ</dc:creator>
      <dc:date>2022-10-03T12:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Correctly parsing webhook requests for both endpoints for both Hubspot and Stripe APIs</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Correctly-parsing-webhook-requests-for-both-endpoints-for-both/m-p/701909#M57540</link>
      <description>&lt;P&gt;Hi! Do you have experience with stripe and hubspot integrations? I am trying to get meta data and payment info into contact info in hubspot...really struggling!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 15:31:28 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Correctly-parsing-webhook-requests-for-both-endpoints-for-both/m-p/701909#M57540</guid>
      <dc:creator>CLahiff</dc:creator>
      <dc:date>2022-10-04T15:31:28Z</dc:date>
    </item>
  </channel>
</rss>

