Create connectors/hubspot_connector.py
Browse files
connectors/connectors/hubspot_connector.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, json
|
| 2 |
+
from cdata.hubspot import connect # pip install cdata-hubspot
|
| 3 |
+
|
| 4 |
+
_conn = connect(PrivateAppToken=os.getenv("HUBSPOT_TOKEN"))
|
| 5 |
+
|
| 6 |
+
def hs_query(sql: str) -> str:
|
| 7 |
+
"""Run SQL against HubSpot objects (Contacts, Deals, etc.)."""
|
| 8 |
+
cur = _conn.cursor()
|
| 9 |
+
cur.execute(sql)
|
| 10 |
+
cols = [d[0] for d in cur.description]
|
| 11 |
+
rows = [dict(zip(cols, r)) for r in cur.fetchall()]
|
| 12 |
+
return json.dumps(rows)
|