APIs & Integrations

CGuillo
Member

Python issues with API connexion

SOLVE

Hi 🙂 

I have been trying to fetch data from Hubspot with Python and I am completely lost now. Hopefully someone can help 🙏

 

I have got the API key, created a test dev account, created an app, got the cliend id, the client secret, pip installed Hubspot in Anaconda and done this (code found in the documentation):

 

from hubspot import HubSpot
api_client = HubSpot(api_key='...')

from hubspot.auth.oauth import ApiException

try:
tokens = api_client.auth.oauth.default_api.create_token(
grant_type="authorization_code",
redirect_uri='http://localhost',
client_id='client_id',
client_secret='client_secret',
code='code'
)
except ApiException as e:
print("Exception when calling create_token method: %s\n" % e)

I am still missing the code that I have no idea how to find despite reading the documentation. AND I also get this error message which doesn't even seem linked to the missing code:

AttributeError: 'Discovery' object has no attribute 'default_api'

 
Can anyone help please? 
Thanks a lot! Corentin

0 Upvotes
1 Accepted solution
KMurray
Solution
Participant

Python issues with API connexion

SOLVE

I believe we are doing similar things.  If you are using Python, I also assume you are using the hubspot-client-api library.  

 

If so, I would use your test account and create a private app there.  Use the api and ability to accept the private app token.  Unless you are developing for the marketplace, I suggest to keep it simple and go the private app route in your test account and then move your code to a private app in the production account.  

 

my_token = 'pat-xxx-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

api_client = HubSpot()
api_client.access_token = my_token
 
Let me know how that works out for you.
 
Kevin

View solution in original post

5 Replies 5
NArtadi
Contributor

Python issues with API connexion

SOLVE

Hi, if it helps, I changed default_api to search_api and it worked for me:

api_response = client.crm.objects.notes.search_api.do_search(public_object_search_request=public_object_search_request)
 
0 Upvotes
sylvain_tirreau
Participant

Python issues with API connexion

SOLVE

Hi,

 

If you follow back Python Hubspot package source code, you'll see the class Discovery (packages/hubspot/discovery/crm/contacts/discovery.py) has no "default_api" method, but has a "basic_api" one. I think the method name has changed since the redaction of API documentation.

 

So, If you write api_client.auth.oauth.basic_api.create_token... it will works.

 

Hope this help

0 Upvotes
CGuillo
Member

Python issues with API connexion

SOLVE

Hi Kevin, Hi Dennis,

thanks a lot for answering! 

 

I did what you suggested @KMurray and I don't have an error message when doing so! 🙂 
BUT When I try to call, for example: 

api_client.crm.contacts.get_all()

I get an error message 😞 

MaxRetryError: HTTPSConnectionPool(host='api.hubapi.com', port=443): Max retries exceeded with url: /crm/v3/objects/contacts?limit=100 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))

 

Any idea on what I am doing wrong here?

 

Thanks again! 🙏

Corentin

0 Upvotes
KMurray
Solution
Participant

Python issues with API connexion

SOLVE

I believe we are doing similar things.  If you are using Python, I also assume you are using the hubspot-client-api library.  

 

If so, I would use your test account and create a private app there.  Use the api and ability to accept the private app token.  Unless you are developing for the marketplace, I suggest to keep it simple and go the private app route in your test account and then move your code to a private app in the production account.  

 

my_token = 'pat-xxx-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

api_client = HubSpot()
api_client.access_token = my_token
 
Let me know how that works out for you.
 
Kevin
dennisedson
HubSpot Product Team
HubSpot Product Team

Python issues with API connexion

SOLVE

@JBeatty  is a smart fellow and I think might be the right person to help you out here

Also, how do we feel about all the snake references in python 😬🐍

0 Upvotes