Discovery object has no attribute basic_api

Hi Everyone,
with the v4 api, I’m trying to get the associations, I just upgraded hubspot api from 7.0.0 to 9.0.0, but its the same code which runs well on the documentation website but doesn’t work when I run it on my laptop.
I’ve the following environment
IDE: JupyterNotebook
Python Version: 3.11.3
hubspot-api-client: 9.0.0

script is as follow

try:
 api_response = client.crm.associations.v4.basic_api.get_page(object_type="contact", object_id="4115", to_object_type="2-118112", limit=10)
 pprint(api_response)
except ApiException as e:
 print("Exception when calling basic_api->get_page: %s\n" % e)

the error message:

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

when I check dir with

dir(client.crm.associations)

i get the following

['class',
'delattr',
'dict',
'dir',
'doc',
'eq',
'format',
'ge',
'getattribute',
'getstate',
'gt',
'hash',
'init',
'init_subclass',
'le',
'lt',
'module',
'ne',
'new',
'reduce',
'reduce_ex',
'repr',
'setattr',
'sizeof',
'str',
'subclasshook',
'weakref',
'_configure_api_client',
'_default_api_factory',
'batch_api',
'config',
'types_api',
'v4']

Hi @ARasool07 and welcome to the Community!
We are so glad to have you here!
Thank you for asking the Community!
I have found a similar post “Read Associations v4 Python AttributeError: ‘BasicApi’ object has no attribute 'get_crm_v4_objects_o” for you where the replies from @zach_threadint might help you!
Also, @PIntegration have you been able to solve this, please?
If anybody else has anything to add and/or share, please feel free to join in the conversation :slightly_smiling_face:
Thanks a lot and have a lovely day!
Best,
Bérangère

Hi @ARasool07 :waving_hand:

Looks like it’ll be a version compatibility issue. I’ve managed to get the relevant API docs example Python code to work (which is consistent with the example you’ve supplied) in a HubSpot Workflow custom code action (Python 3.9, HS Client v8). I generally avoid using the client libraries (mainly because of these compatibility / documentation issues), in favour of the Python “requests” library. In this case, you could do something like:

import requests
import os

# replace placeholders as required
endpoint = "https://api.hubapi.com/crm/v4/objects/{FROM_OBJECT_TYPE}/{FROM_RECORD_ID}/associations/{TO_OBJECT_TYPE}"
params = {
 "limit": 10
}
# replace ACCESS_TOKEN with your private access token
headers = {
 "Authorization": "Bearer {}".format(ACCESS_TOKEN)
}
response = requests.get(endpoint, params=params, headers=headers)
if response.status_code == 200:
 print(response.json())
else:
 print(response.status_code)
 print(response.text)

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

Hi @zach_threadint thanks for the tip, yes it worked with request liberary, I’ll surely keep your tip in mind for future to use requests and avoid clients as much as possible. Thanks a lot.