Links

Create deal

Tags: #hubspot #crm #sales #deal #naas_drivers #snippet
Author: Florent Ravenel​
Description : This notebook create a deal in HubSpot.

Input

Import libraries

from naas_drivers import hubspot
import naas

Setup HubSpot

👉 Starting November 30, 2022, HubSpot API keys no longer enable access to HubSpot APIs, so in Naas version 2.8.3 and above, you need create a private app and use the access token.
Enter Your Access Token
HS_ACCESS_TOKEN = naas.secret.get("HS_ACCESS_TOKEN") or "YOUR_HS_ACCESS_TOKEN"
Enter deal parameters
dealname = "TEST"
closedate = None #must be in format %Y-%m-%d
amount = None
hubspot_owner_id = None
Enter deal stage ID
df_pipelines = hubspot.connect(HS_ACCESS_TOKEN).pipelines.get_all()
df_pipelines
dealstage = '5102584'

Model

Create deal using send method

This method will allow you to add any deal properties available in your HubSpot.
deal1 = {"properties":
{
"dealstage": dealstage,
"dealname": dealname,
"amount": amount,
"closedate": closedate,
"hubspot_owner_id": hubspot_owner_id,
}
}
​
deal1 = hubspot.connect(HS_ACCESS_TOKEN).deals.send(send_deal)

Create deal using create method

deal2 = hubspot.connect(HS_ACCESS_TOKEN).deals.create(
dealname,
dealstage,
closedate
)

Output

Display results

deal1
deal2