May 18, 20239:34 AM - edited May 18, 20231:43 PM
Member
How to update oAuth access-token on the fly?
Hello, I'm building a HubSpot public app that should bring all contacts from HubSpot to our system, for the customer to access and interact with the contacts.
The problem statement: Fetching all the contacts in an account is a time taking process and the access token I've generated (using the auth code or refresh token) expires in that time. I've tried setting the access token using the HubSpot NPM package, but that doesn't seem to work. Any help/suggestion in this regard is appreciated.
You have to Generate a new access token, Use the @hubspot/api-client package, and Call the createToken method. you can use the createToken method from the tokensApi object of the hubspotClient instance. Pass the appropriate parameters, including your client ID, client secret, and refresh token.
After all this, u will be able to update the access token on the fly and continue making API requests without interruption. Remember to handle any errors that may occur during the token refreshing process and implement appropriate error handling and retry mechanisms if needed.