Update connectors/hubspot_connector.py
Browse files
connectors/hubspot_connector.py
CHANGED
|
@@ -5,25 +5,30 @@ import json
|
|
| 5 |
from hubspot import HubSpot
|
| 6 |
from hubspot.crm.contacts import ApiException as HSContactsError
|
| 7 |
|
| 8 |
-
#
|
| 9 |
HUBSPOT_TOKEN = os.getenv("HUBSPOT_TOKEN")
|
| 10 |
|
| 11 |
-
# Setup client
|
| 12 |
client = HubSpot(access_token=HUBSPOT_TOKEN)
|
| 13 |
|
| 14 |
def list_contacts(limit=100):
|
| 15 |
-
"""Return first N contacts as JSON."""
|
| 16 |
try:
|
| 17 |
-
|
| 18 |
-
return json.dumps([r.to_dict() for r in
|
| 19 |
-
except HSContactsError as
|
| 20 |
-
return json.dumps({"error":
|
| 21 |
except Exception as e:
|
| 22 |
return json.dumps({"error": str(e)})
|
| 23 |
|
| 24 |
def list_companies(limit=100):
|
| 25 |
try:
|
| 26 |
-
|
| 27 |
-
return json.dumps([r.to_dict() for r in
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
return json.dumps({"error": str(e)})
|
|
|
|
| 5 |
from hubspot import HubSpot
|
| 6 |
from hubspot.crm.contacts import ApiException as HSContactsError
|
| 7 |
|
| 8 |
+
# Read HubSpot Private App Token
|
| 9 |
HUBSPOT_TOKEN = os.getenv("HUBSPOT_TOKEN")
|
| 10 |
|
|
|
|
| 11 |
client = HubSpot(access_token=HUBSPOT_TOKEN)
|
| 12 |
|
| 13 |
def list_contacts(limit=100):
|
|
|
|
| 14 |
try:
|
| 15 |
+
results = client.crm.contacts.basic_api.get_page(limit=limit).results
|
| 16 |
+
return json.dumps([r.to_dict() for r in results])
|
| 17 |
+
except HSContactsError as he:
|
| 18 |
+
return json.dumps({"error": he.body})
|
| 19 |
except Exception as e:
|
| 20 |
return json.dumps({"error": str(e)})
|
| 21 |
|
| 22 |
def list_companies(limit=100):
|
| 23 |
try:
|
| 24 |
+
results = client.crm.companies.basic_api.get_page(limit=limit).results
|
| 25 |
+
return json.dumps([r.to_dict() for r in results])
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return json.dumps({"error": str(e)})
|
| 28 |
+
|
| 29 |
+
def list_deals(limit=100):
|
| 30 |
+
try:
|
| 31 |
+
results = client.crm.deals.basic_api.get_page(limit=limit).results
|
| 32 |
+
return json.dumps([r.to_dict() for r in results])
|
| 33 |
except Exception as e:
|
| 34 |
return json.dumps({"error": str(e)})
|