Rename connectors/salesforce_connector.py to connectors/hubspot_connector.py
Browse files
connectors/hubspot_connector.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### FILE: connectors/hubspot_connector.py
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
from hubspot import HubSpot
|
| 6 |
+
from hubspot.crm.contacts import ApiException as HSContactsError
|
| 7 |
+
|
| 8 |
+
# Initialize HubSpot client
|
| 9 |
+
HUBSPOT_TOKEN = os.getenv("HUBSPOT_TOKEN")
|
| 10 |
+
hs_client = HubSpot(access_token=HUBSPOT_TOKEN)
|
| 11 |
+
|
| 12 |
+
def query_hubspot(object_type: str, limit: int = 100) -> str:
|
| 13 |
+
"""
|
| 14 |
+
Fetch up to `limit` objects of type `contacts`, `companies`, or `deals`.
|
| 15 |
+
Example: object_type="contacts"
|
| 16 |
+
"""
|
| 17 |
+
try:
|
| 18 |
+
api = getattr(hs_client.crm, object_type)
|
| 19 |
+
page = api.basic_api.get_page(limit=limit)
|
| 20 |
+
items = [r.to_dict() for r in page.results]
|
| 21 |
+
return json.dumps(items)
|
| 22 |
+
except HSContactsError as he:
|
| 23 |
+
return json.dumps({"error": he.body})
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return json.dumps({"error": str(e)})
|
connectors/salesforce_connector.py
DELETED
|
@@ -1,22 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Salesforce connector using CData JDBC bridge.
|
| 3 |
-
Set env vars:
|
| 4 |
-
SF_USER, SF_PASS, SF_TOKEN
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
import os, json
|
| 8 |
-
from cdata.salesforce import connect
|
| 9 |
-
|
| 10 |
-
_conn = connect(
|
| 11 |
-
User = os.getenv("SF_USER"),
|
| 12 |
-
Password = os.getenv("SF_PASS"),
|
| 13 |
-
SecurityToken = os.getenv("SF_TOKEN"),
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
def sf_query(sql: str) -> str:
|
| 17 |
-
"""Execute SQL against Salesforce and return JSON rows."""
|
| 18 |
-
cur = _conn.cursor()
|
| 19 |
-
cur.execute(sql)
|
| 20 |
-
cols = [d[0] for d in cur.description]
|
| 21 |
-
rows = [dict(zip(cols, r)) for r in cur.fetchall()]
|
| 22 |
-
return json.dumps(rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|