APIs & Integrations

DOConnellCB
Member

Get Company details associated with Pipeline?

SOLVE

Hello,
I am new to the API and I have had some success making individual calls to items.  The issue I am having right now is trying to link together objects in the proper way.  If the answer is "You need to make two separate API calls", that is OK.  I am just wondering if I am missing something. 

 

What I am trying to do: I want to generate a list of Companies (id, name, state) that are associated with a Deal that is part of a specific Pipeline.   I have figured out how to get a list of Deals for a specific Pipeline using the "/crm/v3/objects/deals/search" API (since I have the Pipeline ID), but I don't know how to get a list of the Companies with that collection of Deals in one API call.  I have found that we have and "Association" from Deal to Company (named "deal_to_company") but I am not sure how to get the Company details from that Association.

 

I hope I am explaining the problem clearly enough and I appreciate any and all help!

 

Thanks!

Denis

0 Upvotes
1 Accepted solution
zaklein
Solution
Contributor | Diamond Partner
Contributor | Diamond Partner

Get Company details associated with Pipeline?

SOLVE

Hi Denis,

 

I see a couple of approaches that might help -- the most efficient choice probably depends on how much data you're working with and your exact use case:

 

1.  Use the GET Deals endpoint (https://developers.hubspot.com/docs/api/crm/deals) with the "associations" and "properties" query parameters to loop over all Deals, looking for Deal records with the target pipeline ID and then grabbing any returned Company ID(s) as desired (note that you'll have to consider pagination if you're working with >100 Deals). The main problem with this approach is the requirement to loop over all Deals in the given HubSpot account, looking for records that belong to the target pipeline ID -- this probably isn't a huge issue if you're working with say 500 Deals, but could be too time-consuming if you're working with, for example, 5,000+ Deals. Regardless, here's an example:

  • GET  api.hubapi.com/crm/v3/objects/deals?limit=100&archived=false&properties=pipeline&associations=company&hapikey=YOUR_HAPIKEY
  • An individual record returned from this call should look something like this (where I think you'll be interested in associations.companies.results[0].id) -->

 

 

{
    "id": "12345",
    "properties": {
        "createdate": "2019-10-15T09:26:15.098Z",
        "hs_lastmodifieddate": "2021-02-10T18:46:46.090Z",
        "hs_object_id": "12345",
        "pipeline": "98765"
    },
    "createdAt": "2019-10-15T09:26:15.098Z",
    "updatedAt": "2021-02-10T18:46:46.090Z",
    "archived": false,
    "associations": {
        "companies": {
            "results": [
                {
                    "id": "345678",
                    "type": "deal_to_company"
                }
            ]
        }
    }
}

 

 

 

2. As you mention in your message, you could perform multiple calls to the CRM Search endpoint (https://developers.hubspot.com/docs/api/crm/search). Depending on how many Deals you're working with, this will likely be more efficient than option 1. I've hit the same hurdle in the past, where I wanted to return associated record data based on a search, but I've not yet found a solution for achieving this in 1 call to CRM Search. You'll want to keep in mind that API call limits to CRM Search tend to be a little more restrictive than most other endpoints.

 

I hope that's helpful 🙂

All the best,

Zach

View solution in original post

2 Replies 2
DOConnellCB
Member

Get Company details associated with Pipeline?

SOLVE

Thank you Zach!  That is very helpful information.  I am going to use your suggestions.  Our dataset is relatively small, so I will probably go with the idea of looping through my result set to get the company information.  I appreciate the help! 

0 Upvotes
zaklein
Solution
Contributor | Diamond Partner
Contributor | Diamond Partner

Get Company details associated with Pipeline?

SOLVE

Hi Denis,

 

I see a couple of approaches that might help -- the most efficient choice probably depends on how much data you're working with and your exact use case:

 

1.  Use the GET Deals endpoint (https://developers.hubspot.com/docs/api/crm/deals) with the "associations" and "properties" query parameters to loop over all Deals, looking for Deal records with the target pipeline ID and then grabbing any returned Company ID(s) as desired (note that you'll have to consider pagination if you're working with >100 Deals). The main problem with this approach is the requirement to loop over all Deals in the given HubSpot account, looking for records that belong to the target pipeline ID -- this probably isn't a huge issue if you're working with say 500 Deals, but could be too time-consuming if you're working with, for example, 5,000+ Deals. Regardless, here's an example:

  • GET  api.hubapi.com/crm/v3/objects/deals?limit=100&archived=false&properties=pipeline&associations=company&hapikey=YOUR_HAPIKEY
  • An individual record returned from this call should look something like this (where I think you'll be interested in associations.companies.results[0].id) -->

 

 

{
    "id": "12345",
    "properties": {
        "createdate": "2019-10-15T09:26:15.098Z",
        "hs_lastmodifieddate": "2021-02-10T18:46:46.090Z",
        "hs_object_id": "12345",
        "pipeline": "98765"
    },
    "createdAt": "2019-10-15T09:26:15.098Z",
    "updatedAt": "2021-02-10T18:46:46.090Z",
    "archived": false,
    "associations": {
        "companies": {
            "results": [
                {
                    "id": "345678",
                    "type": "deal_to_company"
                }
            ]
        }
    }
}

 

 

 

2. As you mention in your message, you could perform multiple calls to the CRM Search endpoint (https://developers.hubspot.com/docs/api/crm/search). Depending on how many Deals you're working with, this will likely be more efficient than option 1. I've hit the same hurdle in the past, where I wanted to return associated record data based on a search, but I've not yet found a solution for achieving this in 1 call to CRM Search. You'll want to keep in mind that API call limits to CRM Search tend to be a little more restrictive than most other endpoints.

 

I hope that's helpful 🙂

All the best,

Zach