APIs & Integrations

Fawad
Member

Retrieve contacts along with all deals

SOLVE

Dear Hubspot Community,

 

I am new to Hubspot and I am trying to use the APIs for getting all deals. When I retrieve my deals, I also want to retrieve the associated contact details with each deal. I have also read the CRM association API, but I am not sure how I can use it through API. If anyone knows about it, please guide me, I have been stuck here for a few days.

 

I would greatly appreciate any assistance.

 

Thank you!

0 Upvotes
1 Accepted solution
LMeert
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Retrieve contacts along with all deals

SOLVE

Hi @Fawad,

If you want to get the contacts associated with each deal, you will have to (in order) :

  1. Make a call to the deals API (list deals) or use the search API with filters to get a reduced number of deals (which you are already doing)
  2. Iterate over the list of deals and make a call to the associations API. to get all the contacts associated with each deal :

 

/crm/v4/objects/DEALS/{DEAL_ID}/associations/CONTACTS​

 

This call above will get your all the contacts associated to the deal whose id is {DEAL_ID}.

  1. For each association returned, make a call to the contacts API to get more information related to the contacts returned. Use the search call and in your filter specify a contact list and as your filter operator select "IN"

 

    {
      "filters": [
        {
          "value": "string",
          "values": [
            "string"
          ],
          "propertyName": "hs_object_id",
          "operator": "IN"
        }
      ]
    }​

 

 

This is the "simple" way of doing what you want to do.

Of course you can speed this up by using batch calls instead of iterating on the deals one by one.
There's a good solution provided in another thread, and I would recommend this approach.

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

View solution in original post

1 Reply 1
LMeert
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Retrieve contacts along with all deals

SOLVE

Hi @Fawad,

If you want to get the contacts associated with each deal, you will have to (in order) :

  1. Make a call to the deals API (list deals) or use the search API with filters to get a reduced number of deals (which you are already doing)
  2. Iterate over the list of deals and make a call to the associations API. to get all the contacts associated with each deal :

 

/crm/v4/objects/DEALS/{DEAL_ID}/associations/CONTACTS​

 

This call above will get your all the contacts associated to the deal whose id is {DEAL_ID}.

  1. For each association returned, make a call to the contacts API to get more information related to the contacts returned. Use the search call and in your filter specify a contact list and as your filter operator select "IN"

 

    {
      "filters": [
        {
          "value": "string",
          "values": [
            "string"
          ],
          "propertyName": "hs_object_id",
          "operator": "IN"
        }
      ]
    }​

 

 

This is the "simple" way of doing what you want to do.

Of course you can speed this up by using batch calls instead of iterating on the deals one by one.
There's a good solution provided in another thread, and I would recommend this approach.

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !