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.
Point your browser 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 (860...
in the preceding example). You will need the code for the following step.Send the following POST request, substituting your
clientID
,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 }
Note that 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.20.11.jar /path/to/openidm/connectors/
Start IDM with the configuration for the HubSpot sample:
/path/to/openidm/startup.sh -p samples/sync-with-hubspot
Configure the HubSpot connector.
You can do this by updating
samples/sync-with-hubspot/conf/provisioner.openicf-hubspot.json
with your HubSpotclientID
,clientSecret
, andrefreshToken
, and setting"enabled" : true
.Alternatively, 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 configure the connector through the Admin UI, the connection is tested as soon as you select Save.
Reconcile your HubSpot contacts with the IDM managed user repository 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/recon?_action=recon&mapping=systemHubspotContact_managedUser&waitForCompletion=true"
{ "_id": "1f148024-45b9-4dc1-9c3f-29976e02db00-3768", "state": "SUCCESS" }
Alternatively, in the Admin UI, select Configure > Mappings, and 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.
Edit one of the newly created managed users in IDM.
The easiest way to do this is to select Manage > User, select a user to edit, and change one of the user properties.
Reconcile the managed user repository with your HubSpot contacts 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/recon?_action=recon&mapping=managedUser_systemHubspotContact&waitForCompletion=true"
{ "_id": "1f148024-45b9-4dc1-9c3f-29976e02db00-8700", "state": "SUCCESS" }
Alternatively, in the Admin UI, select Configure > Mappings, and select Reconcile on the
managedUser_systemHubspotContact
mapping.Verify that the contact was updated correctly in HubSpot.
This is the end of the sample. For more information about the HubSpot connector, see "HubSpot Connector".