How to generate the refresh token for a Webhook App

Highlighted
New Contributor

Hi there,

 

I have created an app and authorized it with a HubSpot account but I am unsure how I now generate the refresh token so the app appears in the connected apps section so I can add it to the portal. The app is only used for a webhook I want to fire when a contact is updated or created. 

 

Thanks,

Adrian

Reply
0 Upvotes
3 Replies 3
HubSpot Moderator

Hi @adrian11,

 

Take a look at our Oauth overview documentation here: https://developers.hubspot.com/docs/methods/oauth2/oauth2-overview. In particular, the steps outlined for initiating an Oauth connection ("Connecting your app to HubSpot using OAuth 2.0"). It sounds like you've done that first step, which is to generate the authentication URL for your app, and then send a user to that URL. After they've logged in and selected their account, they grant permissions to the content being requested. Our Oauth server then redirects the user back to the redirect URI that you've defined in your app.

 

That takes you to step 2 in the steps outlined in that documentation. There's a code in the URL that the user gets redirected to. This code needs to be exchanged for the refresh token and an initial access token. We have documentation on that here:https://developers.hubspot.com/docs/methods/oauth2/get-access-and-refresh-tokens. The code that you use to get the refresh token and initial access token is short-lived (I think it might be 10 minutes), so you'll need to generate a new one after that time period if you didn't use it. Also, access tokens expire after 6 hours, so when the access token expires, you need to generate a new access token using the refresh token.

 

After those first 2 steps (so after the code has been exchanged for the refresh token and initial access token), the app will show up on the integrations page in the account.

 

I hope that helps. Let me know if you have any questions about it.

Leland Scanlan

HubSpot Developer Support
Reply
0 Upvotes
New Contributor

Hi lscanlan,

 

I need the token to not expire. People are going to be updating Hubspot and it then needs to trigger the webhook so I can update another site without the user needing to do anything besides updating the contact in Hubspot. How are they supposed to generate a new token every time they update a contact? This defeats the purpose of a webhook being triggered automatically.

 

I also dont get why I need built some code on some external platform to just allow a Huspot app work when Hubspot is updated, it seems counter intuitive.

 

Thanks,

Adrian

Reply
0 Upvotes
HubSpot Moderator

Hi @adrian11 , just to add some color here, if you're just using webhooks you only need to install the app to your account.  An app is only installed once you initially exchange the code from your redirect URI to generate access and refresh tokens. Tokens in this case will not matter unless you were making requests to the HubSpot APIs with those tokens you got back. Since it doesn't sound like you are, simply generating the access and refresh tokens will suffice to install your app and start using Webhooks indefinitely.

Reply
0 Upvotes