Oauth2 Refresh Token (Hubspot)

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?

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.

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

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

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!! :smiley:

Still no success! :frowning:
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:

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

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.

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

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.

1 Like

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

@jwaldrip welcome to the community.

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

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

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

Got released with [email protected]

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

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

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! :slight_smile:

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

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?

@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.