> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refold.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Building a HubSpot integration

> This tutorial will give an example of how to create a HubSpot integration that syncs contacts from your app to your Linked account's HubSpot account.

## Pre-requisites

1. HubSpot App is enabled in Refold.
2. HubSpot OAuth app credentials added to Refold. Refer [here](https://docs.gocobalt.io/resources/integration-providers/hubspot#acquiring-hubspot-client-credentials).
3. Trigger created in Refold. Refer [here](https://docs.gocobalt.io/guides/workflow/triggers).
4. Linked Account available. Refer [here](https://docs.gocobalt.io/guides/platform/linked-account).

## Building a Workflow

#### 1. Create Workflow in app

* Go to your [`Apps catalog`](https://app.gocobalt.io/apps) in **Refold** > Search for `HubSpot` > `Workflows` > `Add Workflow` > Choose `Manually` > Give it a name and click on `Add Workflow`.

<img height="200" src="https://mintcdn.com/cobalt-55/lcADCqUGrbz-iIZQ/images/Hubspot/hubspot_workflow.png?fit=max&auto=format&n=lcADCqUGrbz-iIZQ&q=85&s=ba39c0cd6a22b43589808a9506ffadae" alt="Navigation for Workflow setup" data-path="images/Hubspot/hubspot_workflow.png" />

#### 2. Adding the Trigger

To add a trigger for a Workflow in Refold, you need to select details about the Trigger like the Type and which trigger to be implemented.

To add a Trigger, follow these steps:

* Click on the **Start node** to add a trigger.
* In the right side, select the **Type** and the **Trigger** and click on the `Add Trigger` button.

<img height="200" src="https://mintcdn.com/cobalt-55/lcADCqUGrbz-iIZQ/images/Hubspot/hubspot_start.png?fit=max&auto=format&n=lcADCqUGrbz-iIZQ&q=85&s=8ffb9e907f231164a5ad071d5b917feb" alt="Start Node Trigger" data-path="images/Hubspot/hubspot_start.png" />

For this Workflow, we have created an Event `Contact Create` which contains the payload like the first name, last name, email etc. about the event sent by you to HubSpot.

#### 3. Adding the HubSpot Action

* From `Actions`, add a HubSpot node to the workflow.

<img height="200" src="https://mintcdn.com/cobalt-55/lcADCqUGrbz-iIZQ/images/Hubspot/hubspot_action.png?fit=max&auto=format&n=lcADCqUGrbz-iIZQ&q=85&s=b3edd1b243a9c9988e29b00f7b7a6584" alt="HubSpot Node" data-path="images/Hubspot/hubspot_action.png" />

* Click on the node and select an Action from the `Choose an Action` dropdown menu and click on `Save`.

<Warning>
  Before clicking on `Save`, make sure that you have entered data for all the mandatory fields whichever required.
</Warning>

* Connect the two nodes by clicking on `+` button on the `Start` node and dragging the arrow to the **HubSpot** node.

#### 4. Publishing the Workflow

* To publish the workflow, click on the `Publish` button in the top, **Select Environments** of the Workflow and click on `Publish`.

<img height="200" src="https://mintcdn.com/cobalt-55/lcADCqUGrbz-iIZQ/images/Hubspot/hubspot_publish.png?fit=max&auto=format&n=lcADCqUGrbz-iIZQ&q=85&s=a4ae201923b93b56edde1a3aeec107b3" alt="Publish Workflow" data-path="images/Hubspot/hubspot_publish.png" />

## Enabling the Workflow

To enable a workflow, end user or a Linked Account needs to Toggle On the Workflow after connecting with the application.

* Navigate to the Linked Account in which the Workflow needs to be enabled by getting its' **Hosted URL**.

<img height="200" src="https://mintcdn.com/cobalt-55/JZIwRzAqkgW8vPoP/images/Salesforce/Salesforce_linked.png?fit=max&auto=format&n=JZIwRzAqkgW8vPoP&q=85&s=299ceef4856775339eefb9415723bb55" alt="Navigate to Linked Account" data-path="images/Salesforce/Salesforce_linked.png" />

* Go to the Hosted URL and select **HubSpot** from `Manage your Integrations` list.
* Click on the `Connect` button, review the permissions and allow them for a successful connection.
* After a successful connection, you can see the `Configure` section in the HubSpot Application page.
* Enable the Workflow **Sync Contacts** by turning the **toggle On** and click on `Save`.

<img height="200" src="https://mintcdn.com/cobalt-55/lcADCqUGrbz-iIZQ/images/Hubspot/hubspot_enable.png?fit=max&auto=format&n=lcADCqUGrbz-iIZQ&q=85&s=ecc0465aca682013c22e8cda1826a922" alt="Enable Workflow in Linked Account" data-path="images/Hubspot/hubspot_enable.png" />

## Fire an App Event

Lastly, we'll fire an App Event whenever a contact is created in your app by using the Workflow.

* Navigate to `Try API` in **Refold**.
* Choose the **Linked Account** created to test the workflow, select the **Event** and `HubSpot` as the **Application**.
* Click on the `Fire Event` button in the top right.

<img height="200" src="https://mintcdn.com/cobalt-55/lcADCqUGrbz-iIZQ/images/Hubspot/hubspot_fire.png?fit=max&auto=format&n=lcADCqUGrbz-iIZQ&q=85&s=78988230e48e35ea7cb7d0952a691157" alt="Fire an App Event" data-path="images/Hubspot/hubspot_fire.png" />

* You can check the status of the event by navigating to `Logs` > `Events` in **Refold**.

Congratulations! We have successfully built a HubSpot integration that syncs new contacts from your app to the Linked Account's HubSpot.
