Syncing Hubspot with Drupal

I’m working on a project that creates an eCommerce bridge between Drupal and Hubspot. We’ve implemented the task of enabling the bridge and syncing contacts/deals/products/line items between Drupal and Hubspot via sync messages. That is working fine.

Our next task is to sync changes between Hubspot to Drupal. So, if changes are made on the Hubspot contacts/deals we’d like them to be synced with Drupal as well. We’d like to run a cron task every day that queries Hubspot to get the changes made to contacts/deals on Hubspot that haven’t been synced with Drupal yet.

So, my question is, what is the best way to go about it. From the documentation, I see that there are two options: webhooks and making API calls. We’d like to defer on the webhooks implementation for the time-being as the chances of notifications being lost could be an issue because we have a huge data bank that will be updated quite frequently. So, that leaves us with the API calls.

The current confusion I have with it though, is, if we run an API call to get the recently update contacts, will it just fetch the contacts that were updated directly on Hubspot? Or will it also fetch contacts that were updated from other integrations, for example, the Drupal to Hubspot sync? Because that could potentially cause a circular loop, where, we sync contacts from Drupal to Hubspot, then, in the API call to sync between Hubspot and Drupal, it also pulls in those contacts updated from Drupal.

Is there a way we can specify in the API call to fetch only changes made directly on Hubspot?

Hi, @snavas.

Thanks for posting; I appreciate all the detail!

In the long run, I think webhook subscriptions may indeed be your best bet, but let’s talk about polling for now.

Endpoints like Get recently updated and created contacts will return all new and recently modified contacts, regardless of source.

While there isn’t a way for the API to exclude updates made by your or other apps, you can include the propertyMode=value_and_history parameter to see each property’s value history in a versions array. The source-type and source-id fields alongside each value reflect who or what updated the property.

For example:

"properties": {
 "firstname": {
 "value": "Isaac",
 "versions": [
 {
 "value": "Isaac",
 "source-type": "IMPORT",
 "source-id": "a8e67286-08a9-4965-84bb-dc6001a06910",
 "source-label": "First Name",
 "timestamp": 1558707463109,
 "selected": false
 }
 ]
 }

Changes made by your OAuth app should have the "source-type": "INTEGRATIONS" and a source-id of your app ID. You can then exclude these contacts or deals on your end.

I should note that the Get recently modified [and created] deals endpoint uses slightly different syntax. Instead ofpropertyMode=value_and_history, you would useincludePropertyVersions=true. Deals also use source and sourceId fields instead of source-type and source-id.

The HubSpot-Drupal connector is now live and is free to use. HubSpot Marketplace