File size: 1,093 Bytes
0f53d94
e969ea3
 
 
 
 
 
5c279ec
e969ea3
 
0f53d94
 
 
 
5c279ec
 
 
 
0f53d94
 
 
 
e969ea3
5c279ec
 
 
 
 
 
 
 
 
e969ea3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# connectors/hubspot_connector.py

import os
import json
from hubspot import HubSpot
from hubspot.crm.contacts import ApiException as HSContactsError

# Read HubSpot Private App Token
HUBSPOT_TOKEN = os.getenv("HUBSPOT_TOKEN")

client = HubSpot(access_token=HUBSPOT_TOKEN)

def list_contacts(limit=100):
    try:
        results = client.crm.contacts.basic_api.get_page(limit=limit).results
        return json.dumps([r.to_dict() for r in results])
    except HSContactsError as he:
        return json.dumps({"error": he.body})
    except Exception as e:
        return json.dumps({"error": str(e)})

def list_companies(limit=100):
    try:
        results = client.crm.companies.basic_api.get_page(limit=limit).results
        return json.dumps([r.to_dict() for r in results])
    except Exception as e:
        return json.dumps({"error": str(e)})

def list_deals(limit=100):
    try:
        results = client.crm.deals.basic_api.get_page(limit=limit).results
        return json.dumps([r.to_dict() for r in results])
    except Exception as e:
        return json.dumps({"error": str(e)})