Hubspot
Manage your sales pipeline thanks to our connection with the CRM Hubspot.
HubSpot | Inbound Marketing, Sales, and Service Software
Website

Connect

You must "Connect" before any other methods
1
from naas_drivers import hubspot
2
​
3
# Enter your credentials
4
auth_token = "YOUR_AUTH_TOKEN"
5
​
6
# Connect to hubspot
7
hs = hubspot.connect(auth_token)
Copied!
In the drivers philosophy, we did not raise errors.

Contacts

Get

All users

1
# Get all contacts
2
df_contact = hs.contacts.get_all()
3
df_contact
Copied!

Single user

1
# Get single contact
2
contact_id = "1"
3
hs.contacts.get(contact_id)
Copied!

Create

Basic

1
# Contact parameters
3
​
4
# With create method
5
contact_id = hs.contacts.create(email)
Copied!

Advanced

1
# Contact parameters
3
firstname = "Test"
4
lastname ='CASHSTORY'
5
phone = "+33600000000"
6
jobtitle = "Consultant"
7
website = "www.cashstory.com"
8
company = 'CASHSTORY'
9
hubspot_owner_id = 1
10
​
11
# With create method
12
contact_id = hs.contacts.create(email,
13
firstname,
14
lastname,
15
phone,
16
jobtitle,
17
website,
18
company,
19
hubspot_owner_id)
Copied!

With json

1
# Contact parameters
3
firstname = "Test"
4
lastname ='CASHSTORY'
5
phone = "+33600000000"
6
jobtitle = "Consultant"
7
website = "www.cashstory.com"
8
company = 'CASHSTORY'
9
hubspot_owner_id = 1
10
​
11
# With send method
12
create_contact = {"properties":
13
{
14
"email": email,
15
"firstname": firstname,
16
"lastname": lastname,
17
"phone": phone,
18
"jobtitle": jobtitle,
19
"website": website,
20
"company": company,
21
"hubspot_owner_id": hubspot_owner_id,
22
}
23
}
24
​
25
contact_id = hs.contacts.send(create_contact)
Copied!

Update

Basic

1
# Contact parameters
2
contact_id = "1"
4
​
5
# With update method
6
hs.contacts.update(contact_id, email)
Copied!

Advanced

1
# Contact parameters
2
contact_id = "1"
4
firstname = "Test"
5
lastname ='CASHSTORY'
6
phone = "+33600000000"
7
jobtitle = "Consultant"
8
website = "www.cashstory.com"
9
company = 'CASHSTORY'
10
hubspot_owner_id = 1
11
​
12
# With update method
13
hs.contacts.update(contact_id,
14
email,
15
firstname,
16
lastname,
17
phone,
18
jobtitle,
19
website,
20
company,
21
hubspot_owner_id)
Copied!

With json

1
# With patch method
2
update_contact = {"properties":
3
{
4
"email": email,
5
"firstname": firstname,
6
"lastname": lastname,
7
"phone": phone,
8
"jobtitle": jobtitle,
9
"website": website,
10
"company": company,
11
"hubspot_owner_id": hubspot_owner_id,
12
}
13
}
14
​
15
hs.contacts.patch(contact_id, update_contact)
Copied!

Delete

1
# Delete deals
2
contact_id = "1"
3
hs.contacts.delete(contact_id)
Copied!

Deals

Get

All deals

1
# Get all deals
2
hs.deals.get_all()
Copied!

Single deal

1
# Get single deal
2
get_deal = '1'
3
hs.deals.get(get_deal)
Copied!

Create

Basic

1
# Deal parameters
2
dealname = "NEW DEAL"
3
dealstage = '1'
4
​
5
# With create method
6
deal_id = hs.deals.create(dealname,
7
dealstage)
Copied!

Advanced

1
# Deal parameters
2
dealname = "NEW DEAL"
3
dealstage = "1"
4
closedate = "01/01/2021"
5
amount = 1000.00
6
hubspot_owner_id = 1
7
​
8
# With create method
9
deal_id = hs.deals.create(dealname,
10
dealstage)
Copied!

With json

1
# Deal parameters
2
dealname = "NEW DEAL"
3
dealstage = "1"
4
closedate = "01/01/2021"
5
amount = 1000.00
6
hubspot_owner_id = 1
7
​
8
# With send method
9
send_deal = {"properties":
10
{
11
"dealstage": dealstage,
12
"dealname": dealname,
13
"amount": amount,
14
"closedate": closedate,
15
"hubspot_owner_id": hubspot_owner_id,
16
}
17
}
18
​
19
deal_id = hs.deals.send(send_deal)
Copied!

Update

Basic

1
# Deal parameters
2
deal_id = "1"
3
dealname = "NEW DEAL"
4
​
5
# With update method
6
hs.deals.update(deal_id,
7
dealname)
Copied!

Advanced

1
# Deal parameters
2
deal_id = "1"
3
dealname = "NEW DEAL"
4
dealstage = "1"
5
closedate = "01/01/2021"
6
amount = 1000.00
7
hubspot_owner_id = 1
8
​
9
# With update method
10
hs.deals.update(deal_id,
11
dealname,
12
dealstage,
13
closedate,
14
amount,
15
hubspot_owner_id)
Copied!

With json

1
# Deal parameters
2
deal_id = "1"
3
dealname = "NEW DEAL"
4
dealstage = "1"
5
closedate = "01/01/2021"
6
amount = 1000.00
7
hubspot_owner_id = 1
8
​
9
# With patch method
10
update_deal = {"properties":
11
{
12
"dealstage": dealstage,
13
"dealname": dealname,
14
"amount": amount,
15
"closedate": closedate,
16
"hubspot_owner_id": hubspot_owner_id,
17
}
18
}
19
​
20
hs.deals.patch(deal_id, update_deal)
Copied!

Delete

1
# Delete deals
2
deal_id = "1"
3
hs.deals.delete(deal_id)
Copied!

Associate

Get

1
# Get association
2
object = 'deal'
3
object_id = '1'
4
association = 'contact'
5
​
6
hs.associations.get(object,
7
object_id,
8
association)
Copied!

Create

1
# Create association
2
object = 'deal'
3
object_id = '1'
4
associate = 'contact'
5
associate_id = '1'
6
​
7
hs.associations.create(object,
8
object_id,
9
associate,
10
associate_id)
Copied!

Pipelines

Get all pipelines

1
# Get all pipelines
2
hs.pipelines.get_all()
Copied!

Deal stages

Get all dealstages

1
# Get all dealstages
2
hs.dealstages.get_all()
Copied!

Official documentation

HubSpot APIs | Getting started