Retreiving companies with their contacts


#1

I have a question regarding the usage of the API. We have an application in which we want to synchronize all companies with their contacts from the hubspot API of our client. The goal is that the HubSpot database acts as a single source of truth for our application.

Right now we do so by recursively calling GetAllCompanies until we retreived all the companies. This is done in about 40 calls, as there seemingly is no way to retreive a full list. As, understandably, the API is throttled this process takes at least 4 seconds to complete.

The problem occurs when trying to fetch all of these companies’ contacts. As we’re talking about more than 4000 companies, we need to do 4000 calls to retrieve all contact details per company. This makes the synchronization process very slow due to the earlier mentioned throttling (we’re talking about minutes now).

When looking into the api documentation I can not find a method to do this more efficiently:

  • I could not find a way to fetch the companies with their contacts in one call instead of paginated.
  • Retrieving only the modified results from the past 30 days most likely will return a dataset that is about the same is size as the company will be very active.

Is there something I’m overlooking? What would be the best practice in this case?


#2

To add to this: Instead of synchronizing all companies and contacts I thought I’d look into searching directly via the API. In this specific use-case that would be sufficient. However I cannot find any documentation on this.

Perhaps someone of the development team can share me the best practices in this case? When I emailed HubSpot directly they directed me here as the place to ask these kind of questions.


#3

Hi @Yann_aliens,

Just to make sure that we’re on the same page, are you looking to pull all existing companies and contacts from HubSpot in order to look at the associations and update your external application? If that’s the case, you’ll need to use the bulk companies & contacts APIs to pull everything. Making one request per company to pull that company’s contact probably isn’t the most efficient way to get everything, though. When pulling contacts/companies, the records will include their associations. Using the bulk contacts API (see below) to pull all of your contacts, and then associating the records on your end would likely be quicker since you could make fewer requests.

As to keeping your database in sync with HubSpot; it’s not necessary to pull all of your HubSpot companies and contacts every time you’re syncing your external app. Once everything is synced initially, you can use the webhooks API to subscribe to contact updates, allowing you to get notified when associations change. You can also periodically poll the recently updated contacts endpoint to look for updates to contact/company associations.


#4

Dear Derek,

Thank you for your reply!

The case you’re describing is indeed what we are trying to achieve. Loading both lists (companies and contacts) separately and then merging them on our side is something we looked into. However we discarded this idea as in the example of the JSON output of the ‘Get all contacts API’ I do not see the id of the company to which it belongs. Do you perhaps have more information on how we could achieve such a merging operation?

Kind regards,
Yann


#5

Hi @Yann_aliens,

I see; I didn’t mention this explicitly, but to get the contact’s associatedCompanyId from that endpoint, you’ll need to specify it using the optional property query parameter. If you were to do that, the example URL from that doc would look like this:

https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=demo&count=2&property=associatedCompanyId


#6

Hi Derek,

Thanks again for your reply. I will try this as soon as possible, it sounds like a solution!