APIs & Integrations

tjsimpson
Participante

hubspot crm api refresh token

resolver

I am hoping to get some guidance on writing to the HubSpot CRM API.

 

I am using the following to pull data from HubSpot via Azure Data Factory:
Client ID
Client Secret
Access Token
Refresh Token

My understanding is the access_token expires every 30 minutes but the refresh_token will continue to refresh this. This connection has been working for 7 days now.
Does this refresh token expire? I have seen some places saying that it does not, and seeing it has worked for 7 days I am assuming this will continue to work.

Now when I go to write to the HubSpot API have an issue where my access_token is expired. I would think there is a way to use the refresh_token in the API POST?

Here is an example where I get the expiration response:

import hubspot
from pprint import pprint
from hubspot.crm.deals import BatchInputSimplePublicObjectInputForCreate, ApiException

client = hubspot.Client.create(
    access_token="placeholder"
    )


batch_input_simple_public_object_input_for_create = BatchInputSimplePublicObjectInputForCreate(inputs=[
    {"properties":
     {
         "dealname":"test"

         },
         "associations":
         [
             {"to":
              {
                  "id":"99999999999"},
              "types":
              [
                  {
                      "associationCategory":"HUBSPOT_DEFINED",
                      "associationTypeId":341
                      }]}]}])
try:
    api_response = client.crm.deals.batch_api.create(batch_input_simple_public_object_input_for_create=batch_input_simple_public_object_input_for_create)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling batch_api->create: %s\n" % e)

 "status":"error","message":"The OAuth token used to make this call expired 5 day(s) ago."

 

Thank you in advance for your help!

0 Avaliação positiva
1 Solução aceita
zach_threadint
Solução
Top colaborador(a)

hubspot crm api refresh token

resolver

Hi @tjsimpson 👋

Based on my experience building HubSpot apps, HubSpot OAuth Refresh Tokens never expire.

You'll either need to:

  1. Immediately before each HubSpot API request (other than OAuth requests), use your refresh token to get a new access token (POST https://api.hubapi.com/oauth/v1/token, as per this HubSpot documentation), or
  2. Store your access tokens and their expiry date in an external database. Then, before each HubSpot API request (other than OAuth requests), check to see if your existing access token is still valid. If not, use your refresh token to get a new one and update your database accordingly (including new access token expiry date).

I hope this proves useful. Please let me know if you have any follow-up questions.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


Exibir solução no post original

0 Avaliação positiva
2 Respostas 2
zach_threadint
Solução
Top colaborador(a)

hubspot crm api refresh token

resolver

Hi @tjsimpson 👋

Based on my experience building HubSpot apps, HubSpot OAuth Refresh Tokens never expire.

You'll either need to:

  1. Immediately before each HubSpot API request (other than OAuth requests), use your refresh token to get a new access token (POST https://api.hubapi.com/oauth/v1/token, as per this HubSpot documentation), or
  2. Store your access tokens and their expiry date in an external database. Then, before each HubSpot API request (other than OAuth requests), check to see if your existing access token is still valid. If not, use your refresh token to get a new one and update your database accordingly (including new access token expiry date).

I hope this proves useful. Please let me know if you have any follow-up questions.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Avaliação positiva
tjsimpson
Participante

hubspot crm api refresh token

resolver

@zach_threadint 

Thank you for the response! I was actually able to figure this out and forgot I had the post still up. I did exactly what you mention on option 1 and it works great.

 

Best,

Tyler Simpson