What is the best way to retrieve all contacts in hubspot as well as some company properties

SOLVE
PieterVHeerden
Member
 
Hi all. We would like to get all contacts once a day to sync it to an external system.
This is a short term solution to sync once a day and we can have as many as 15 000 contacts or more.
 
We need the contact info as well as some basic company details we specify that a contact is associated with. so we dont want to do 2 calls
  1. get contact details,
  2. then get company info for this contact.
  3. how can we do this in one call if we need to process batch calls for contacts

the json we pass back will be contact info and some basic company properties x 15 000

 

Thanks

1 Accepted solution

Accepted Solutions
MichaelC
Solution
Guide | Partner

@dennisedson 

 

I would not really call all 15 000 contact and all of the associations and then all the companies based on the associations in one call period. 

 

If I would do it I would set up a cron job to call a script every minute or so. I would also create a custom property for a contact called "last sync with my system" and set it to datetime format. 

 

That script would call contacts via the search api looking for the property "last sync with my system" with a date less then x. 

https://developers.hubspot.com/docs/api/crm/contacts (endpoint search) 

 

Then I would get an array of contacts depending on what date I set to x and how many contacts that where syncronized to long ago. 

With this array of contact I would use the associations API to get a list of all the companies connected with each contact. 

https://developers.hubspot.com/docs/api/crm/associations

 

Then I would get an array of companies (usually only one company associated with one contact - but there can be more). With this I would use the company API to get company data if I needed it. 

https://developers.hubspot.com/docs/api/crm/companies

 

 

If I need specific company properties or specific contact properties I would add ?properties=mypropertyname&properties=asecondproperty to the adress bar in my get call in the API. 

 

@PieterVHeerden 

To answer your questions:

1. Use the objects - contacts API and list the properties you want to recieve from contacts within the adress bar

2. First use the associations api (listed above) then you will get the company id (hubspot internal id for the companies) with that you can then use the company api to recieve the company data. 

3. You cant. At least 3 calls to get contacts, associations and companies. The workload on the servers to get that amount of contacts, associations and companies in one call would not be good for traffic and you might get a result (limit) of maybe a 100 companies (im not sure what the limits are here ) per call - and you would need to call the seconds page and a third page and so on untill you get all the results you request. With that said there are also call limits on how many requests you can do per minute (one page = one request) and you would pass that limit by far if you need to contact 15000 contacts at once. 

 

So my advice is to create a property - call it something with date - update it whenever you have done your search - and do maybe 100 calls per minute using cron jobs or similar. 

 

Best regards,

Michael 



Need further help with integrations or business development?



Want to help me?

Go to the following links and read through the ideas. If you like them - give the idea an upvote

Upvote the following ideas:

View solution in original post

3 Replies 3
dennisedson
Community Manager

@MichaelC , how would you recommend handling this?

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
MichaelC
Solution
Guide | Partner

@dennisedson 

 

I would not really call all 15 000 contact and all of the associations and then all the companies based on the associations in one call period. 

 

If I would do it I would set up a cron job to call a script every minute or so. I would also create a custom property for a contact called "last sync with my system" and set it to datetime format. 

 

That script would call contacts via the search api looking for the property "last sync with my system" with a date less then x. 

https://developers.hubspot.com/docs/api/crm/contacts (endpoint search) 

 

Then I would get an array of contacts depending on what date I set to x and how many contacts that where syncronized to long ago. 

With this array of contact I would use the associations API to get a list of all the companies connected with each contact. 

https://developers.hubspot.com/docs/api/crm/associations

 

Then I would get an array of companies (usually only one company associated with one contact - but there can be more). With this I would use the company API to get company data if I needed it. 

https://developers.hubspot.com/docs/api/crm/companies

 

 

If I need specific company properties or specific contact properties I would add ?properties=mypropertyname&properties=asecondproperty to the adress bar in my get call in the API. 

 

@PieterVHeerden 

To answer your questions:

1. Use the objects - contacts API and list the properties you want to recieve from contacts within the adress bar

2. First use the associations api (listed above) then you will get the company id (hubspot internal id for the companies) with that you can then use the company api to recieve the company data. 

3. You cant. At least 3 calls to get contacts, associations and companies. The workload on the servers to get that amount of contacts, associations and companies in one call would not be good for traffic and you might get a result (limit) of maybe a 100 companies (im not sure what the limits are here ) per call - and you would need to call the seconds page and a third page and so on untill you get all the results you request. With that said there are also call limits on how many requests you can do per minute (one page = one request) and you would pass that limit by far if you need to contact 15000 contacts at once. 

 

So my advice is to create a property - call it something with date - update it whenever you have done your search - and do maybe 100 calls per minute using cron jobs or similar. 

 

Best regards,

Michael 



Need further help with integrations or business development?



Want to help me?

Go to the following links and read through the ideas. If you like them - give the idea an upvote

Upvote the following ideas:

View solution in original post

PieterVHeerden
Member

hi Michael,

 

Thanks for the detailed explination.

The steps you provided above is what I had in mind, except the date field example for last synced. This just means i would need to do an update per contacts as well to keep the sunced date populated as well. The only problem is, the system that is calling us to get the nifo cannot confirm and write data back to us, so, ideally I dont want to update the last synced date unless I know it was synced. I will chew on this a bit more.

 

.I was hoping there would be a better way but I understand the limitation mentioned here. I appreciate the quick response and community feedback.

 

Thanks