DEV Community

Cover image for How to create Hubspot contact using API in NodeJS
matkoklaic
matkoklaic

Posted on

How to create Hubspot contact using API in NodeJS

Get the API key in Settings -> Integrations -> API Key section of the Hubspot dashboard.

Install the Hubspot API client package:

npm install @hubspot/api-client --save
Enter fullscreen mode Exit fullscreen mode

or using yarn:

yarn add @hubspot/api-client
Enter fullscreen mode Exit fullscreen mode

Import the Hubspot API client library:

const hubspot = require('@hubspot/api-client');
Enter fullscreen mode Exit fullscreen mode

Instantiate Hubspot API client:

const hubspotClient = new hubspot.Client({
    apiKey: process.env.HUBSPOT_API_KEY,
});
Enter fullscreen mode Exit fullscreen mode

Create Hubspot contact:

const properties = {
  email: 'user@example.com',
  firstname: 'Jack',
  lastname: 'Jones',
}
const { response, body } =
  await hubspotClient.crm.contacts.basicApi.create({
    properties,
  });
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.