APIs & Integrations

rtyshyk
Participant

CRM API. Deal search with Company relation

SOLVE

Hi there,

 

I have to find multiple Deal with Company relations (in general I need only the company name and ID). 

 

I use  /crm/v3/objects/deals/search endpoint and it's fine, but then I need to get somehow Companies for my Deals.

 

I see that you have "/crm/v3/objects/deals/{dealId}/associations/{toObjectType}" but I have to call it for each deal, what is crazy when I have hundreds of deals.

 

Read batch "/crm/v3/objects/deals/batch/read" has no any information about associations. 

 

Any ideas on how I can query the Company name for a Deal for a reasonable time?

 

2 Accepted solutions
ChrisoKlepke
Solution
Key Advisor | Elite Partner
Key Advisor | Elite Partner

CRM API. Deal search with Company relation

SOLVE

Hey @rtyshyk , 

 

I totally hear your hassle. This very inconvenient to deal with (pun intended), especially if you don't know how much you will be receiving with your calls. You then end up creating for loops and all of those things, which feels very heavy and slow. 

 

Luckily, HubSpot got into the GraphQL game and there is a beta right now you can sign up to. I recommend this left and right because HubSpot has a lot of power with its associations, but accessing them from outside can be tricky.

 

Here is the announcement 

https://developers.hubspot.com/changelog/expanding-the-graphql-beta-for-cms-developers

 

Here is the documentation

https://developers.hubspot.com/docs/cms/data/query-hubspot-data-using-graphql

 

GraphQL is a query language that allows you to access more at once with one call/query. It might look something like this for you:

 

query contactsWithAssociatedCompany {
  CRM {
    contact_collection {
      items {
        firstname
        lastname
        associations {
          company_collection__primary {
            items {
              name
              address
            }
          }
        }
      }
    }
  }
}

 

 

This is the API endpoint:

 

https://api.hubapi.com/collector/graphql

 

 

Hope this helps you get going. If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I'd really appreciate it. 

 

Cheers, 

Chriso

View solution in original post

LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

CRM API. Deal search with Company relation

SOLVE

Hi @rtyshyk,

 

I had the same problem and there's a little workaround that may help you do without the graph QL option:

Use the search endpoint on the companies object, and use your previous id list as a filter as follows

{
    "filters" : [
        {
            "propertyName" : "associations.deal",
            "operator": "IN",
            "values": ["8260189334", "87847557"] <-- list of IDs goes there
        }
    ],
    "properties" : ["firstname", "email"]
}

 

This only works if you just need to get the list, but won't if you need to get which company is associated with it since the results are not in the order of the ids in the values list.

Maybe with a helper property automatically populated with a workflow you can link them back together using this method.

 

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

7 Replies 7
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

CRM API. Deal search with Company relation

SOLVE

Hi @rtyshyk,

 

I had the same problem and there's a little workaround that may help you do without the graph QL option:

Use the search endpoint on the companies object, and use your previous id list as a filter as follows

{
    "filters" : [
        {
            "propertyName" : "associations.deal",
            "operator": "IN",
            "values": ["8260189334", "87847557"] <-- list of IDs goes there
        }
    ],
    "properties" : ["firstname", "email"]
}

 

This only works if you just need to get the list, but won't if you need to get which company is associated with it since the results are not in the order of the ids in the values list.

Maybe with a helper property automatically populated with a workflow you can link them back together using this method.

 

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 !

rtyshyk
Participant

CRM API. Deal search with Company relation

SOLVE

Hi @LMeert 

 

Thanks for a workaround, but names without relations do not make sense in my case.

I also thought about simple text properties and automation when the company is assigned to the deal., it looks like the most efficient solution so far. 

 

rtyshyk
Participant

CRM API. Deal search with Company relation

SOLVE

Hello @ChrisoKlepke 

 

GraphQL requires CMS Professional subscription, so no way to try it 🙂

 

Thanks anyway.

ChrisoKlepke
Key Advisor | Elite Partner
Key Advisor | Elite Partner

CRM API. Deal search with Company relation

SOLVE

Hey @rtyshyk , 

 

that's unfortunate, you don't have the fitting license for it. Thank you for still accepting this as a solution.

 

Cheers, 

Chriso

0 Upvotes
rtyshyk
Participant

CRM API. Deal search with Company relation

SOLVE

Hi @ChrisoKlepke 

 

Thank you for a quick response.  I will definitely try it.

 

Cheers,

Roman

 

 

ChrisoKlepke
Solution
Key Advisor | Elite Partner
Key Advisor | Elite Partner

CRM API. Deal search with Company relation

SOLVE

Hey @rtyshyk , 

 

I totally hear your hassle. This very inconvenient to deal with (pun intended), especially if you don't know how much you will be receiving with your calls. You then end up creating for loops and all of those things, which feels very heavy and slow. 

 

Luckily, HubSpot got into the GraphQL game and there is a beta right now you can sign up to. I recommend this left and right because HubSpot has a lot of power with its associations, but accessing them from outside can be tricky.

 

Here is the announcement 

https://developers.hubspot.com/changelog/expanding-the-graphql-beta-for-cms-developers

 

Here is the documentation

https://developers.hubspot.com/docs/cms/data/query-hubspot-data-using-graphql

 

GraphQL is a query language that allows you to access more at once with one call/query. It might look something like this for you:

 

query contactsWithAssociatedCompany {
  CRM {
    contact_collection {
      items {
        firstname
        lastname
        associations {
          company_collection__primary {
            items {
              name
              address
            }
          }
        }
      }
    }
  }
}

 

 

This is the API endpoint:

 

https://api.hubapi.com/collector/graphql

 

 

Hope this helps you get going. If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I'd really appreciate it. 

 

Cheers, 

Chriso

jamieroyce-mc
Contributor

CRM API. Deal search with Company relation

SOLVE

Thanks Chriso! This will save a LOT of needless API calls and loops!

0 Upvotes