DEV Community

Cover image for Import Contacts from HubSpot to Salesforce
Lizz Parody
Lizz Parody

Posted on

Import Contacts from HubSpot to Salesforce

In this blog post, you will learn how to easily import contacts from HubSpot to Salesforce with a few clicks using Fusebit.

Contact in HubSpot
Image description

Contact sync in Salesforce
Image description

Create HubSpot and Salesforce integration

  1. Sign up or log in to Fusebit
  2. Click on “New Integration”. Choose HubSpot Contacts sync in the middle column, and change the integration name and the HubSpot Connector name (optional). Click on Create. Image description
  3. In the right column “Connectors”, click on Add new, or Link existing and create a Salesforce connector. Image description As a Salesforce and HubSpot user, you can create powerful integrations between the two systems with code.

Click on “Edit” in the middle column, and replace the code with:

const { Integration } = require('@fusebit-int/framework');

const integration = new Integration();
const router = integration.router;

const hubspotConnector = 'hubspot';
const sfdcConnector = 'salesforce';

router.post('/api/tenant/:tenantId/sync', integration.middleware.authorizeUser('install:get'), async (ctx) => {
  const hubspotClient = await integration.tenant.getSdkByTenant(ctx, hubspotConnector, ctx.params.tenantId);
  const sfdcClient = await integration.tenant.getSdkByTenant(ctx, sfdcConnector, ctx.params.tenantId);
  const contacts = await hubspotClient.crm.contacts.getAll();
  await Promise.all(contacts.map(async (contact) => {
    const res = await sfdcClient.sobject('Contact').create({LastName: contact.properties.lastname, Email: contact.properties.email, FirstName: contact.properties.firstname})
  }))
  ctx.body = `Successfully performed initial import from hubSpot to SFDC.`;
});

integration.event.on('/:componentName/webhook/:eventtype', async (ctx) => {
    const hubspotClient = await integration.service.getSdk(ctx, hubspotConnector, ctx.req.body.installIds[0])
    const sfdcClient = await integration.service.getSdk(ctx, sfdcConnector, ctx.req.body.installIds[0]);
    const contact = await hubspotClient.crm.contacts.basicApi.getById(ctx.req.body.data.objectId);
    await sfdcClient.sobject('Contact').create({LastName: contact.properties.lastname, Email: contact.properties.email, FirstName: contact.properties.firstname})
});

module.exports = integration;
Enter fullscreen mode Exit fullscreen mode

Keep in mind to change the constants hubspotConnectorand sfdcConnector with your own connector name.

Now that you have both connectors and the integration logic let’s configure HubSpot and Salesforce.

To Configure HubSpot Developers and Connect to Salesforce, click here

One Last Thing…

If you have any questions, you can contact us. Keep in mind that you can create any HubSpot Salesforce integration using Fusebit, filter contact activity, get contact data, advanced setup and sync data between the two platforms.

If you want to use other platforms, create powerful bi-directional sync and improve your customer experience, for example sending new Salesforce leads to your marketing team in slack, check out Fusebit, and follow us on Twitter!

Top comments (1)

Collapse
 
assistroco profile image
Assistro

Hey there,

Anyone using HubSpot here?

Check out our new tool to make your work life easier : assistro.co