Skip to main content

HubSpot

HubSpot offers a full platform of marketing, sales, customer service, and CRM software to help businesses

Credential configuration

To configure this credential you can use one or more of your API KEY, your Access token and your Developer API KEY.

Optionally you can set any of the extra config params you can find in the examples of this page.

Here you have an example of a filled credential configuration form in YepCode:

HubSpot snippets available in editor

note

The title is the triggering text for YepCode to autocomplete the script

Integration

New integration from credential
const hubspotClient = yepcode.integration.hubspot('yepcode-hubspot')
New integration from plain authentication data
const hubspot = require('@hubspot/api-client')
const hubspotClient = new hubspot.Client({ apiKey: 'YOUR_API_KEY' })

Contacts

Get contacts
const limit = 5
const after = 0
const properties = ['firstname', 'lastname', 'company']
await hubspotClient.crm.contacts.basicApi
.getPage(limit, after, properties)
.then(({ results }) => {
console.log(`Retrieved ${results.length} contacts`)
})
Search contacts
const filter = {
propertyName: 'createdate',
operator: 'GTE',
value: Date.now() - 30 * 60000
}
const filterGroup = { filters: [filter] }
const sort = JSON.stringify({
propertyName: 'createdate',
direction: 'DESCENDING'
})
const query = 'test'
const properties = ['createdate', 'firstname', 'lastname']
const limit = 100
const after = 0

await hubspotClient.crm.contacts.searchApi
.doSearch({
filterGroups: [filterGroup],
sorts: [sort],
query,
properties,
limit,
after
})
.then(({ total, results }) => console.log(total, results))
Create contact
const response = await hubspotClient.crm.contacts.basicApi.create({
properties: {
firstname: firstname,
lastname: lastname
}
})
console.log('Created contact with id ${response.id}')

Companies

Get companies
const limit = 5
const after = 0
const properties = ['firstname', 'lastname', 'company']
await hubspotClient.crm.companies.basicApi
.getPage(limit, after, properties)
.then(({ results }) => {
console.log(`Retrieved ${results.length} companies`)
})
Create company
const response = await hubspotClient.crm.companies.basicApi.create({
properties: {
firstname: firstname,
lastname: lastname
}
})
console.log('Created company with id ${response.id}')

Associations

Associate contact with company
await hubspotClient.crm.companies.associationsApi.create(
company.id,
"contacts",
contact.id,
"company_to_contact"
);