APIs & Integrations

HSuryvanshi
Member

I am not able to call this API: client.crm.lists.lists_api.do_search

Error: 'Discovery' object has no attribute 'lists_api'

def get_hubspot_lists(access_token, params😞
    client = hubspot.Client.create(access_token=access_token)
   
    try:
        # Retrieve all lists
        list_search_request = ListSearchRequest(
            offset=0,
            count=0,
            additional_properties=["string"]
        )
        response = client.crm.lists.lists_api.do_search(
            list_search_request=list_search_request
        )
        headers = {
            'Authorization': f'Bearer {access_token}',
            'Content-Type': 'application/json'
        }
        output = {
            "companies": [],
            "contacts": []
        }
       
        for lists in response.results:
            if lists.object_type_id == "0-1":
                object_type = "contacts"
            else:
                object_type = "companies"
               
            url = f"https://api.hubapi.com/crm/v3/lists/{lists.id}/memberships"
            response = requests.get(url, params=params, headers=headers)
            response_data = response.json()
           
            if response_data.get("results"😞
                record = [record["recordId"] for record in response_data["results"]]
                if object_type == 'companies':
                    output["companies"].extend(record)
                elif object_type == 'contacts':
                    output["contacts"].extend(record)
                   
        return output
   
    except Exception as e:
        # Handle exceptions
        print(f"Error: {e}")
        return None
0 Upvotes
1 Reply 1
Jaycee_Lewis
Community Manager
Community Manager

I am not able to call this API: client.crm.lists.lists_api.do_search

Hey, @HSuryvanshi If you are updated to the most recent version of the Python SDK, you might want to try opening an Issue here https://github.com/HubSpot/hubspot-api-python/issues. We can also leave this open here in case other Python-proficient members of the community might have a suggestion for you.

 

Best,

Jaycee


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !
0 Upvotes