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
-
Browse to the following URL:
https://app.hubspot.com/oauth/authorize?client_id=clientID&scope=contacts&redirect_uri=your-domain
-
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
-
Copy the
code
in this URL (860c1867-9e4b-4761-82c4-1a5a4caf5224
from the above example). You will need the code for the following step. -
Send the following POST request, substituting your
clientID
andclientSecret
: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
In this section, you will do the following:
-
Download and install the HubSpot connector.
-
Start IDM with the sample configuration.
-
Configure the HubSpot connector and test your connection to HubSpot.
-
Reconcile your HubSpot contacts with the IDM managed user repository.
-
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.
-
To install the HubSpot connector, download the connector jar from the ForgeRock BackStage download site site and place it in the
/path/to/openidm/connectors
directory:mv ~/Downloads/hubspot-connector-1.5.2.0.jar /path/to/openidm/connectors/
-
Start IDM with the configuration for the HubSpot sample:
cd /path/to/openidm/ ./startup.sh -p samples/sync-with-hubspot
-
To configure the HubSpot connector, do one of the following:
-
Update
samples/sync-with-hubspot/conf/provisioner.openicf-hubspot.json
with your HubSpotclientID
,clientSecret
, andrefreshToken
, and setting"enabled" : true
. -
Use the admin UI to configure the connector.
-
Select Configure > Connectors, and select the HubSpot connector.
-
Complete at least the Base Connector Details and enable the connector.
-
-
-
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. -
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.
-
-
In the admin UI, select Manage > User, and verify that your HubSpot contacts have been created as IDM managed users.
-
In the admin UI, select Manage > User, select a user to edit, and change one of the user properties.
-
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.
-
-
In HubSpot, verify that the contact was updated.
For more information about the HubSpot connector, refer to HubSpot connector.