# connectors/hubspot_connector.py import os import json from hubspot import HubSpot from hubspot.crm.contacts import ApiException as HSContactsError # Get HubSpot token from env HUBSPOT_TOKEN = os.getenv("HUBSPOT_TOKEN") # Setup client client = HubSpot(access_token=HUBSPOT_TOKEN) def list_contacts(limit=100): """Return first N contacts as JSON.""" try: response = client.crm.contacts.basic_api.get_page(limit=limit) return json.dumps([r.to_dict() for r in response.results]) except HSContactsError as e: return json.dumps({"error": e.body}) except Exception as e: return json.dumps({"error": str(e)}) def list_companies(limit=100): try: response = client.crm.companies.basic_api.get_page(limit=limit) return json.dumps([r.to_dict() for r in response.results]) except Exception as e: return json.dumps({"error": str(e)})