Python issues with API connexion

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

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

@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 :grimacing::snake:

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

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! :slightly_smiling_face:
BUT When I try to call, for example:

api_client.crm.contacts.get_all()

I get an error message :disappointed_face:

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

Corentin

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

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)