Interacts with the HubSpot API for creation of contacts and deals. Also includes a request method which can be used to call any API method on the HubSpot API.
Hubspot
Constructor - accepts API Key for HubSpot (for legacy template support), or oauth (for new templates)
Name | Type | Description | |
---|---|---|---|
apiKey |
string
|
[Hubspot API key]. See: https://knowledge.hubspot.com/integrations/how-do-i-get-my-hubspot-api-key |
|
token |
string
|
// Initiate Hubspot, passing in HubSpot API key, which should be stored in a secret
const hubspot = new Hubspot(Mesa.secret.get('hubspot-hapi'));
Void
Name | Type | Description | |
---|---|---|---|
method |
string
|
(GET / POST / PUT / PATCH / DELETE) |
|
endpoint |
string
|
The relative path, e.g. 'contacts/v1/contact' |
|
payload |
object
|
Data to pass to endpoint, |
|
options |
object
|
Optional params See https://developers.getmesa.com/sdk#vendor-mesa.js-mesa.request.get |
Object
response object from HubSpot API
Request to use for new oauth methods
Name | Type | Description | |
---|---|---|---|
method |
string
|
(GET / POST / PUT / PATCH / DELETE) |
|
path |
string
|
The full path, e.g. 'contacts/v1/contact' |
|
payload |
object
|
Data to pass to endpoint, |
|
options |
object
|
Optional params See https://developers.getmesa.com/sdk#vendor-mesa.js-mesa.request.get |
Void
Get HubSpot contact by email
Name | Type | Description | |
---|---|---|---|
string
|
address |
// Initiate Hubspot, passing in HubSpot API key
const hubspot = new Hubspot(Mesa.secret.get('hubspot-hapi'));
// Example call
const response = hubspot.getContactByEmail('[email protected]');
object
response object from HubSpot API
Create a HubSpot Contact
If contact already exists (based on the email address provided in the data), response will show the ID of the existing Contact
Name | Type | Description | |
---|---|---|---|
data |
object
|
Request payload |
|
data.properties |
array
|
Array of Contact Properties. Details on parameters you can use: https://developers.hubspot.com/docs/methods/contacts/create_contact |
// Example payload (must be wrapped with 'properties')
const postData = {
properties:[
{
property: "email",
value: "[email protected]"
},
{
property: "firstname",
value: "John"
},
{
property: "lastname",
value: "Doe"
}
]
};
// Initiate Hubspot, passing in HubSpot API key
const hubspot = new Hubspot(Mesa.secret.get('hubspot-hapi'));
// Example call
const response = hubspot.createContact(postData);
object
response object from HubSpot API
Create or update a HubSpot Contact
Return data includes isNew
parameter which will be set to true
if contact created, or false
if updated
Name | Type | Description | |
---|---|---|---|
data |
object
|
Request payload |
|
data.properties |
array
|
Array of Contact Properties. Details on parameters you can use: https://developers.hubspot.com/docs/methods/contacts/create_or_update |
// Example payload - must be wrapped in 'properties'
const postData = {
properties:[
{
property: "firstname",
value: "John"
},
{
property: "lastname",
value: "Doe"
}
]
};
// Initiate Hubspot, passing in HubSpot API key
const hubspot = new Hubspot(Mesa.secret.get('hubspot-hapi'));
// Example call
const response = hubspot.createOrUpdateContact(postData, '[email protected]');
object
response object from HubSpot API
Create a HubSpot Deal
A deal can be created without associatedVids (contact IDs).
Name | Type | Description | |
---|---|---|---|
data |
object
|
||
data.properties |
array
|
Array of Deal Properties. Details on parameters you can use: https://developers.hubspot.com/docs/methods/deals/create_deal |
// Example payload - must be wrapped in 'properties', and include 'associations' if you want to link a deal to a contact
const postData = {
associations: [
associatedVids: [
123456
]
],
properties: [
{
name: "dealname",
value: "John's first deal",
},
{
name: "dealname",
value: "John's first deal",
},
{
name: "dealstage",
value: "appointmentscheduled",
},
{
name: "dealtype",
value: "newbusiness",
},
{
name: "10.99",
value: "amount",
}
]
};
// Initiate Hubspot, passing in HubSpot API key
const hubspot = new Hubspot(Mesa.secret.get('hubspot-hapi'));
// Example call
const response = hubspot.createDeal(postData);
object
response object from HubSpot API
Create HubSpot workflow
Name | Type | Description | |
---|---|---|---|
data |
object
|
containing JSON data for workflow. Details on parameters you can use: https://developers.hubspot.com/docs/methods/workflows/v3/create_workflow |
// Create JSON payload to pass through (see https://developers.hubspot.com/docs/methods/workflows/v3/create_workflow for structure)
const postData = "{}";
// Initiate Hubspot, passing in HubSpot API key
const hubspot = new Hubspot(Mesa.secret.get('hubspot-hapi'));
// Example call
const response = hubspot.createWorkflow(postData);
object
response object from HubSpot API