# Oauth2 Refresh Token (Hubspot)

**URL:** <https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316>\
**Category:** Questions\
**Created:** [February 13, 2021, 1:05pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316 "2021-02-13T13:05:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [February 13, 2021, 1:05pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/1 "2021-02-13T13:05:18Z")

</div>

Hello,

I’m using http requests to hubspot for additional functionality than the hubspot node. When the oauth2 expires, hubspot returns a 400 error to n8n, the error code they’re using for expired tokens. Looking at other posts here it seems that N8N waits for the 401 response before refreshing the token. Is there any workaround?

---

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [February 13, 2021, 1:07pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/2 "2021-02-13T13:07:28Z")

</div>

Actually, according to the hubspot api logs it’s serving a 401 error, but this is showing as a 400 error in N8N. If I reconnect the oauth in N8N it works fine again until the token expires 6 hours later.

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [February 14, 2021, 1:49am UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/3 "2021-02-14T01:49:50Z")

</div>

@ljcn thanks for letting us know. Will check it out.

---

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [February 14, 2021, 12:18pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/4 "2021-02-14T12:18:15Z")

</div>

Thank you. I hoped it might’ve been because I didn’t use the **grant\_type=refresh\_token** query parameter, but 6 hours later the token’s expired again and N8N is showing a 400 error

---

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [February 14, 2021, 6:56pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/5 "2021-02-14T18:56:34Z")

</div>

Just an update  
I used postman to get an access token from hubspot, which returned a refresh token.  
I’ve passed this refresh token in the parameters via N8N and it’s reconnected.  
Assuming this is the solution, I’ll let you know in 6 hours!! 😃

---

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [February 16, 2021, 11:05am UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/6 "2021-02-16T11:05:12Z")

</div>

Still no success! ☹  
Hubspot expects the **grant\_type=refresh\_token** and **refresh\_token=xxxxxx** to be passed in the body of the Oauth2 request. Is there any way of adding to the body?

Here’s a link to their Documentation:

> **[Refresh OAuth 2.0 access token](https://legacydocs.hubspot.com/docs/methods/oauth2/refresh-access-token)**
>
> POST /oauth/v1/token - Use a previously obtained refresh token to generate a new access token. Access tokens expire after six hours.

N8N still shows a 400 error when the token is expired, but hubspots logs suggest it’s served a 401

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [February 16, 2021, 1:40pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/7 "2021-02-16T13:40:02Z")

</div>

That should be handled for you. What authentication type are you using in the HTTP node? Because you need to use the OAuth2 type. Also, you can generate an API Key in HubSpot and use the authentication Header OAuth.

---

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [February 16, 2021, 1:52pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/8 "2021-02-16T13:52:59Z")

</div>

I’m using Oauth2, it connects fine but doesn’t refresh the token.  
When the token expires it shows as a 400 error in N8N.  
I assumed Oauth2 would be more secure than using a header oauth, but the header one works fine

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [February 16, 2021, 2:06pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/9 "2021-02-16T14:06:18Z")

</div>

Ok, just set up a Hubspot account and connected to it using OAuth2. Once the credentials expires I will test and come back to you.

---

<div class="post-metadata">

**Author:** ![jwaldrip](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jwaldrip/32/3586_2.png) [@jwaldrip](https://community.n8n.io/u/jwaldrip)\
**Post date:** [February 24, 2021, 11:14pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/10 "2021-02-24T23:14:50Z")

</div>

This is affecting us as well. The Hubspot token is never refreshing in n8n.

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [February 24, 2021, 11:19pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/11 "2021-02-24T23:19:51Z")

</div>

@jwaldrip welcome to the community.

As I mentioned in Github, looking into this. Again, thanks for letting us know.

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [February 24, 2021, 11:34pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/12 "2021-02-24T23:34:32Z")

</div>

@jwaldrip @ljcn got fixed. We will let you know when is released.

[https://github.com/n8n-io/n8n/pull/1489](https://github.com/n8n-io/n8n/pull/1489)

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [February 25, 2021, 7:07am UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/13 "2021-02-25T07:07:04Z")

</div>

Just got merged. Will be released with the next version, probably on Monday.

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [March 4, 2021, 11:39am UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/14 "2021-03-04T11:39:51Z")

</div>

Got released with n8n@0.110.0

---

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [March 5, 2021, 10:40pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/15 "2021-03-05T22:40:06Z")

</div>

The token still expires every 6 hours. Am I missing something?

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [March 5, 2021, 10:41pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/16 "2021-03-05T22:41:30Z")

</div>

You just needed to do the OAuth2 flow again. Weird, I tested it and it was working fine.

---

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [March 5, 2021, 10:43pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/17 "2021-03-05T22:43:49Z")

</div>

I’ve reconnected it and created it as a new one. I’ve just put grant\_type=refresh\_token in the url parameter, will let you know in 6 hours! 🙂

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [March 6, 2021, 1:45am UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/18 "2021-03-06T01:45:52Z")

</div>

Ahhh wait. You are using the http request and not the hubspot node?

---

<div class="post-metadata">

**Author:** ![ljcn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ljcn/32/2726_2.png) [@ljcn](https://community.n8n.io/u/ljcn)\
**Post date:** [March 6, 2021, 11:19pm UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/19 "2021-03-06T23:19:53Z")

</div>

Yes, I’m using their associations, crm cards and engagement endpoints so couldn’t do it with the hubspot node. I’ve reverted back to authentication with the api key instead - it’s working fine - and it’s only communicating between an app on localhost and hubspot, so assuming this will be safe enough?

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [March 7, 2021, 1:09am UTC](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316/20 "2021-03-07T01:09:58Z")

</div>

@ljcn gotcha. I thought you were working with the node. I need to have a look a see why it’s not working with the HTTP node. Yes, in the meantime, using the API Key should be safe.

[Next page](https://community.n8n.io/t/oauth2-refresh-token-hubspot/4316.md?page=2)
