Lesson 178 min

How to Connect n8n to HubSpot

Learn how to connect n8n to HubSpot using both action nodes to create contacts and webhook triggers to start workflows from HubSpot events.

How to Connect n8n to HubSpot

This tutorial will guide you through connecting n8n to HubSpot. You will learn how to perform actions in HubSpot, like creating a contact, directly from an n8n workflow. Additionally, you’ll learn how to trigger an n8n workflow when an event occurs in HubSpot, such as a new contact being created, using a reliable webhook method.


Part 1: Perform Actions in HubSpot from n8n

This section covers how to set up the HubSpot node in n8n to create, update, or delete objects in your HubSpot account.

Step 1: Add the HubSpot Node in n8n

  1. In your n8n workflow, click the + icon to add a new node.
  2. Search for HubSpot and select it from the list.
  3. For this example, we will create a new contact. Under Resource, select Contact, and for the Operation, choose Create or Update.

Step 2: Create a HubSpot Developer Account

To connect to HubSpot's API, you need a developer account.

  1. Navigate to developers.hubspot.com.
  2. Click "Create a developer account" and sign up. You can link this to your existing HubSpot account if you have one.

Step 3: Create a Private App in HubSpot

Private apps allow you to generate a secure token for API access.

  1. Once in your developer portal, go to Apps from the navigation menu.
  2. Click "Create app" and select "Private app".
  3. Fill in the required information:
    • App Name: Give it a descriptive name like n8n Integration.
    • Description: Briefly describe its purpose.

Step 4: Configure Scopes (Permissions)

Scopes define what your app is allowed to do in your HubSpot account.

  1. In your app's settings, go to the "Scopes" tab.
  2. You need to grant permissions for the actions you want to perform. To create and read contacts, you need the following scopes:
    • crm.objects.contacts.read
    • crm.objects.contacts.write
  3. Search for and select these scopes. HubSpot has extensive documentation on which scopes are required for each action.
  4. Click "Create app" at the top right. You may get a warning about displaying the access token; click "Continue creating".

Step 5: Get Your Private App Access Token

  1. After the app is created, you will see your Access Token.
  2. Click "Show token" and then "Copy".

⚠️ Important: Treat your Access Token like a password. Do not share it publicly.

Step 6: Configure Credentials in n8n

  1. Go back to the HubSpot node in your n8n workflow.
  2. In the Credential field, select "Create New".
  3. Paste the access token you copied from HubSpot into the "Access Token" field.
  4. Click "Save". You should see a "Connection tested successfully" message.

Step 7: Create a Contact from n8n

  1. With your credential configured, select it from the dropdown.
  2. In the Email field, enter an email address for the new contact, for example, abc@gmail.com.
  3. You can fill in other properties like First Name, Last Name, and any custom fields.
  4. Click "Execute Node".
  5. Check your HubSpot account. The new contact should now appear in your contacts list.

Part 2: Trigger n8n Workflows from HubSpot Events

This section covers how to start an n8n workflow when something happens in HubSpot, like a contact being created. While HubSpot has a trigger node, it can sometimes have issues. The following webhook method is a more robust alternative.

Step 1: Create a Webhook Trigger in n8n

  1. Add a new Webhook node to your n8n workflow. This node will provide a URL that listens for incoming data.
  2. You can customize the Path for clarity, for example, webhook-hubspot.
  3. Copy the Test URL. You will use this to receive test data from HubSpot.

Step 2: Add the Webhook URL to Your HubSpot App

  1. Go back to your private app's settings in the HubSpot developer portal.
  2. Navigate to the "Webhooks" tab.
  3. Paste the n8n Test URL into the Target URL field.

Step 3: Create a Webhook Subscription

Now, tell HubSpot which events should be sent to your webhook.

  1. Click "Create subscription".
  2. Select the Object type you want to monitor, for example, Contact.
  3. Select the Event you want to subscribe to, such as contact.creation.
  4. Click "Save".

Step 4: Test the Trigger

  1. In your n8n workflow, click "Listen for test event" on the Webhook node. It will now wait for data.
  2. In HubSpot, go to CRM > Contacts and create a new contact.
  3. Return to n8n. The Webhook node should capture the event data from HubSpot, including information about the new contact.

Step 5: Route the Workflow Based on the Event

You can create powerful automations by routing your workflow based on the event type.

  1. Add a Switch node after the Webhook node.
  2. The Switch node allows you to add different rules and direct the workflow down different paths.
  3. Set the Property to {{ $json.body[0].subscriptionType }}. This expression retrieves the event type from the webhook data.
  4. Create rules for different events. For example:
    • Rule 1 (Contact Created): Set Value to contact.creation.
    • Rule 2 (Contact Deleted): Set Value to contact.deletion.
  5. Now you can add different action nodes to each output of the Switch node, allowing you to handle contact creations and deletions differently.

You have now successfully set up a two-way integration between n8n and HubSpot, enabling you to both control HubSpot from your workflows and trigger workflows from events in HubSpot.