---
title: Synchronize data between IDM and HubSpot
description: This sample demonstrates bidirectional synchronization between IDM managed users and HubSpot contacts.
component: pingidm
version: 8.1
page_id: pingidm:samples-guide:sync-with-hubspot
canonical_url: https://docs.pingidentity.com/pingidm/8.1/samples-guide/sync-with-hubspot.html
keywords: ["Samples", "Synchronization", "HubSpot"]
section_ids:
  prepare-hubspot-sample: Prepare the sample
  get_the_refresh_token: Get the refresh token
  sample-hubspot-running: Run the sample
---

# Synchronize data between IDM and HubSpot

This sample demonstrates bidirectional synchronization between IDM managed users and HubSpot contacts.

## Prepare the sample

The sample assumes that you have a client app in HubSpot, with the corresponding `clientID`, `clientSecret`, and `refreshToken`, and that you already have some contacts stored in HubSpot.

### Get the refresh token

1. Browse to the following URL:

   ```
   https://app.hubspot.com/oauth/authorize?client_id=clientID&scope=contacts&redirect_uri=your-domain
   ```

2. On the resulting page, select your user account in HubSpot. You are redirected to a URL similar to the following:

   ```
   https://your-domain/?code=860c1867-9e4b-4761-82c4-1a5a4caf5224
   ```

3. Copy the `code` in this URL (`860c1867-9e4b-4761-82c4-1a5a4caf5224` from the above example). You will need the code for the following step.

4. Send the following POST request, substituting your `clientID` and `clientSecret`:

   ```
   curl \
   --request POST \
   --header 'Cache-Control: no-cache' \
   --header 'Content-Type: application/x-www-form-urlencoded' \
   --data 'grant_type=authorization_code&client_id=your-id&client_secret=your-secret&redirect_uri=your-domain&code=code' \
    "https://api.hubapi.com/oauth/v1/token"
   {
     "refresh_token": "f37e1132-xxxx-xxxx-xxxx-xxxx",
     "access_token": "CKbm...VaE",
     "expires_in": 21600
   }
   ```

   |   |                                                                                                                       |
   | - | --------------------------------------------------------------------------------------------------------------------- |
   |   | The `redirect_uri` must be URL-encoded in this request, for example, `redirect_uri=https%3A%2F%2Fwww.example.com%2F`. |

   The output of the POST request includes the `refresh_token` required to configure the connector.

## Run the sample

|   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| - | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|   | Starting with IDM 8.1, the [legacy admin UI is deprecated](../release-notes/deprecated-functionality.html#legacy-admin-ui-deprecated) and is no longer bundled with IDM. New deployments should use the [Platform admin UI](../setup-guide/platform-admin-ui.html), which is the replacement for the legacy admin UI.Both UIs are available as separate downloads from the [Backstage download site](https://backstage.forgerock.com/downloads):- To install the Platform admin UI, follow the steps in [Install the Platform admin UI for standalone IDM](../setup-guide/platform-admin-ui.html).

- To continue using the legacy admin UI, follow the steps in [Install the legacy admin UI](../setup-guide/legacy-admin-ui.html). |

In this section, you will do the following:

1. Download and install the HubSpot connector.

2. Start IDM with the sample configuration.

3. Configure the HubSpot connector and test your connection to HubSpot.

4. Reconcile your HubSpot contacts with the IDM managed user repository.

5. Change a user in IDM and reconcile the changes back to HubSpot.

The mapping configuration file (`sync.json`) for this sample includes two mappings: `systemHubspotContact_managedUser` and `managedUser_systemHubspotContact`. You will use these mappings to reconcile users between IDM and HubSpot.

1. To install the HubSpot connector, download the connector jar from the [Backstage download site](https://backstage.forgerock.com/downloads) site and place it in the `/path/to/openidm/connectors` directory:

   ```
   mv ~/Downloads/hubspot-connector-1.5.20.26.jar /path/to/openidm/connectors/
   ```

2. [Set up DS](start-here.html#ldap-server-config) without importing any LDIF file or [select another repository](../install-guide/chap-repository.html) for the sample.

3. Start IDM with the configuration for the HubSpot sample:

   ```
   cd /path/to/openidm/
   ./startup.sh -p samples/sync-with-hubspot
   ```

4. To configure the HubSpot connector, do one of the following:

   * Update `samples/sync-with-hubspot/conf/provisioner.openicf-hubspot.json` with your HubSpot `clientID`, `clientSecret`, and `refreshToken`, and setting `"enabled" : true`.

   * Use the admin UI to configure the connector.

     1. Select Configure > Connectors, and select the HubSpot connector.

     2. Complete at least the Base Connector Details and enable the connector.

5. Test the connection to HubSpot by running the following command:

   ```
   curl \
   --header "X-OpenIDM-Username: openidm-admin" \
   --header "X-OpenIDM-Password: openidm-admin" \
   --header "Accept-API-Version: resource=1.0" \
   --request POST \
   "http://localhost:8080/openidm/system?_action=test"
   [
     {
       "name": "hubspot",
       "enabled": true,
       "config": "config/provisioner.openicf/hubspot",
       "connectorRef": {
         "bundleVersion": "[1.5.0.0,1.6.0.0)",
         "bundleName": "org.forgerock.openicf.connectors.hubspot-connector",
         "connectorName": "org.forgerock.openicf.connectors.hubspot.HubspotConnector"
       },
       "displayName": "Hubspot Connector",
       "objectTypes": [
         "company",
         "contactProperties",
         "__ALL__",
         "companyProperties",
         "contact"
       ],
       "ok": true
     }
   ]
   ```

   A status of `"ok": true` indicates that the connector can connect to HubSpot.

   |   |                                                                                                            |
   | - | ---------------------------------------------------------------------------------------------------------- |
   |   | If you configured the connector through the admin UI, the connection is tested as soon as you select Save. |

6. To reconcile your HubSpot contacts with the IDM managed user repository, do one of the following:

   * Run the command:

     ```
     curl \
     --header "X-OpenIDM-Username: openidm-admin" \
     --header "X-OpenIDM-Password: openidm-admin" \
     --header "Accept-API-Version: resource=1.0" \
     --request POST \
     "http://localhost:8080/openidm/recon?_action=recon&mapping=systemHubspotContact_managedUser&waitForCompletion=true"
     {
       "_id": "1f148024-45b9-4dc1-9c3f-29976e02db00-3768",
       "state": "SUCCESS"
     }
     ```

   * In the admin UI, select Configure > Mappings, and then select Reconcile on the `systemHubspotContact_managedUser` mapping.

7. In the admin UI, select Manage > User, and verify that your HubSpot contacts have been created as IDM managed users.

8. In the admin UI, select Manage > User, select a user to edit, and change one of the user properties.

9. To reconcile the managed user repository with your HubSpot contacts, do one of the following:

   * Run the command:

     ```
     curl \
     --header "X-OpenIDM-Username: openidm-admin" \
     --header "X-OpenIDM-Password: openidm-admin" \
     --header "Accept-API-Version: resource=1.0" \
     --request POST \
     "http://localhost:8080/openidm/recon?_action=recon&mapping=managedUser_systemHubspotContact&waitForCompletion=true"
     {
       "_id": "1f148024-45b9-4dc1-9c3f-29976e02db00-8700",
       "state": "SUCCESS"
     }
     ```

   * In the admin UI, select Configure > Mappings, and then select Reconcile on the `managedUser_systemHubspotContact` mapping.

10. In HubSpot, verify that the contact was updated.

For more information about the HubSpot connector, refer to [HubSpot connector](https://docs.pingidentity.com/openicf/connector-reference/hubspot.html).
