Skip to main content

HubSpot Integration

The HubSpot integration provides full access to the HubSpot CRM API, including contacts, companies, deals, notes, and workflow automation.

Setup

You must configure HubSpot before using it in your code. Only configured integrations are available to your agent.
1

Open Integrations panel

In your spreadsheet, click Integrations in the left panel (or visit orangeslice.com/spreadsheets/<spreadsheet_id>/edits?panel=integrations)
2

Configure HubSpot

Select HubSpot and enter your HubSpot access token
3

Use in your code

Once configured, access HubSpot via integrations.hubspot

Contacts

Create Contact

const response = await integrations.hubspot.createContact({
  properties: {
    email: '[email protected]',
    firstname: 'John',
    lastname: 'Doe',
    phone: '+1-555-0123',
    company: 'Acme Inc',
    jobtitle: 'CEO'
  },
  associations: [
    {
      to: { id: 'company-id' },
      types: [{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 1 }]
    }
  ]
});

console.log(response.entity.id); // New contact ID

Get Contact

const contact = await integrations.hubspot.getContact('contact-id', {
  properties: ['email', 'firstname', 'lastname', 'phone'],
  associations: ['companies', 'deals']
});

Update Contact

await integrations.hubspot.updateContact('contact-id', {
  properties: {
    lifecyclestage: 'customer',
    hs_lead_status: 'QUALIFIED'
  }
});

Delete Contact

await integrations.hubspot.deleteContact('contact-id');

List Contacts

const contacts = await integrations.hubspot.listContacts({
  limit: 100,
  properties: ['email', 'firstname', 'lastname'],
  associations: ['companies']
});

// Pagination
if (contacts.paging?.next) {
  const nextPage = await integrations.hubspot.listContacts({
    after: contacts.paging.next.after
  });
}

Search Contacts

const results = await integrations.hubspot.searchContacts({
  query: 'john',
  limit: 10,
  properties: ['email', 'firstname', 'lastname'],
  filterGroups: [
    {
      filters: [
        {
          propertyName: 'lifecyclestage',
          operator: 'EQ',
          value: 'lead'
        }
      ]
    }
  ],
  sorts: ['createdate']
});

console.log(`Found ${results.total} contacts`);

Companies

Create Company

const response = await integrations.hubspot.createCompany({
  properties: {
    name: 'Acme Corporation',
    domain: 'acme.com',
    industry: 'Technology',
    numberofemployees: '500',
    annualrevenue: '10000000',
    city: 'San Francisco',
    state: 'CA',
    country: 'USA'
  }
});

Get Company

const company = await integrations.hubspot.getCompany('company-id', {
  properties: ['name', 'domain', 'industry'],
  associations: ['contacts', 'deals']
});

Update Company

await integrations.hubspot.updateCompany('company-id', {
  properties: {
    lifecyclestage: 'customer',
    description: 'Updated company description'
  }
});

Search Companies

const results = await integrations.hubspot.searchCompanies({
  filterGroups: [
    {
      filters: [
        {
          propertyName: 'annualrevenue',
          operator: 'GTE',
          value: '1000000'
        }
      ]
    }
  ],
  properties: ['name', 'domain', 'annualrevenue']
});

Deals

Create Deal

const response = await integrations.hubspot.createDeal({
  properties: {
    dealname: 'Enterprise License',
    amount: '50000',
    dealstage: 'appointmentscheduled',
    pipeline: 'default',
    closedate: '2024-12-31'
  },
  associations: [
    {
      to: { id: 'contact-id' },
      types: [{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 3 }]
    }
  ]
});

Get Deal

const deal = await integrations.hubspot.getDeal('deal-id', {
  properties: ['dealname', 'amount', 'dealstage'],
  associations: ['contacts', 'companies']
});

Update Deal

await integrations.hubspot.updateDeal('deal-id', {
  properties: {
    dealstage: 'closedwon',
    amount: '55000'
  }
});

Search Deals

const results = await integrations.hubspot.searchDeals({
  filterGroups: [
    {
      filters: [
        {
          propertyName: 'dealstage',
          operator: 'EQ',
          value: 'closedwon'
        },
        {
          propertyName: 'amount',
          operator: 'GTE',
          value: '10000'
        }
      ]
    }
  ]
});

Notes

Create Note

const response = await integrations.hubspot.createNote({
  properties: {
    hs_note_body: 'Called the client about renewal',
    hs_timestamp: new Date().toISOString()
  },
  associations: [
    {
      to: { id: 'contact-id' },
      types: [{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 10 }]
    }
  ]
});

Get Note

const note = await integrations.hubspot.getNote('note-id', {
  properties: ['hs_note_body', 'hs_timestamp'],
  associations: ['contacts', 'companies', 'deals']
});

Search Notes

const results = await integrations.hubspot.searchNotes({
  filterGroups: [
    {
      filters: [
        {
          propertyName: 'hs_timestamp',
          operator: 'GTE',
          value: '2024-01-01'
        }
      ]
    }
  ]
});

Workflows (Flows)

List Workflows

const workflows = await integrations.hubspot.listFlows({
  limit: 100
});

for (const flow of workflows.results) {
  console.log(`${flow.name}: ${flow.isEnabled ? 'Active' : 'Inactive'}`);
}

Get Workflow

const flow = await integrations.hubspot.getFlow('flow-id');

console.log(flow.name);
console.log(flow.enrollmentCriteria);
console.log(flow.actions);

Create Workflow

const flow = await integrations.hubspot.createFlow({
  name: 'Welcome Sequence',
  type: 'CONTACT_FLOW',
  objectTypeId: '0-1', // Contacts
  isEnabled: false,
  enrollmentCriteria: {
    type: 'LIST_BASED',
    shouldReEnroll: false,
    unEnrollObjectsNotMeetingCriteria: true,
    listFilterBranch: {
      filterBranchType: 'AND',
      filterBranchOperator: 'AND',
      filterBranches: [],
      filters: [
        {
          filterType: 'PROPERTY',
          property: 'lifecyclestage',
          operation: {
            operationType: 'ENUMERATION',
            operator: 'IS_ANY_OF',
            includeObjectsWithNoValueSet: false,
            values: ['lead']
          }
        }
      ]
    },
    reEnrollmentTriggersFilterBranches: []
  }
});

Update Workflow

await integrations.hubspot.updateFlow('flow-id', {
  revisionId: 'current-revision-id',
  name: 'Updated Welcome Sequence',
  isEnabled: true
});

Delete Workflow

await integrations.hubspot.deleteFlow('flow-id');

Filter Operators

Available operators for search filters:
OperatorDescription
EQEquals
NEQNot equals
LTLess than
LTELess than or equal
GTGreater than
GTEGreater than or equal
BETWEENBetween two values
INIn a list of values
NOT_INNot in a list of values
HAS_PROPERTYHas any value
NOT_HAS_PROPERTYHas no value
CONTAINS_TOKENContains text
NOT_CONTAINS_TOKENDoes not contain text

Types Reference

HubSpotContactProperties

interface HubSpotContactProperties {
  email?: string;
  firstname?: string;
  lastname?: string;
  phone?: string;
  mobilephone?: string;
  company?: string;
  website?: string;
  jobtitle?: string;
  lifecyclestage?: string;
  hubspot_owner_id?: string;
  hs_lead_status?: string;
  [key: string]: string | undefined;
}

HubSpotCompanyProperties

interface HubSpotCompanyProperties {
  name?: string;
  domain?: string;
  description?: string;
  phone?: string;
  website?: string;
  industry?: string;
  numberofemployees?: string;
  annualrevenue?: string;
  city?: string;
  state?: string;
  country?: string;
  zip?: string;
  address?: string;
  lifecyclestage?: string;
  hubspot_owner_id?: string;
  [key: string]: string | undefined;
}

HubSpotDealProperties

interface HubSpotDealProperties {
  dealname?: string;
  amount?: string;
  dealstage?: string;
  pipeline?: string;
  closedate?: string;
  dealtype?: string;
  description?: string;
  hubspot_owner_id?: string;
  hs_priority?: string;
  createdate?: string;
  [key: string]: string | undefined;
}

HubSpotCrmObject

interface HubSpotCrmObject {
  id: string;
  properties: Record<string, string | null>;
  createdAt: string;
  updatedAt: string;
  archived: boolean;
  archivedAt?: string;
  propertiesWithHistory?: Record<string, HubSpotValueWithTimestamp[]>;
}