APIs & Integrations

newera
Member

Get deals based on company id

SOLVE

Hi,

I'm trying to match a deal with a company:

I've used this endpoint to get the companies

 
and then this endpoint go get deals
 
but there is no uid in deals to I can know that is belongs to a company.

Or is there and easier way to get companies that include the deals or how should I link these together.

Thanks in advance
0 Upvotes
1 Accepted solution
coldrickjack
Solution
Guide

Get deals based on company id

SOLVE

Hi @newera,

 

CRM records are associated to one another by a special type of object known as an "Association" object. There is even a dedicated suite of endpoints to interact with this object type (create, read, update and delete associations). 

 

When using the CRM APIs you can include "associations" parameter in your request and specify the name of the associated objects you wish to retrieve. For instance the request below will retrieve all of the companies and any IDs of associated deals.

 

GET https://api.hubapi.com/crm/v3/objects/companies?associations=deals
RESPONSE
{
    "results": [
        {
            "id": "8139119856",
            "properties": {
                "createdate": "2023-07-26T12:30:48.856Z",
                "domain": "nintendo.com",
                "hs_lastmodifieddate": "2023-08-28T13:51:39.121Z",
                "hs_object_id": "8139119856",
                "name": "Nintendo"
            },
            "createdAt": "2023-07-26T12:30:48.856Z",
            "updatedAt": "2023-08-28T13:51:39.121Z",
            "archived": false,
            "associations": {
                "deals": {
                    "results": [
                        {
                            "id": "8330464724",
                            "type": "company_to_deal"
                        },
                        {
                            "id": "8330517224",
                            "type": "company_to_deal"
                        },
                        {
                            "id": "8511793392",
                            "type": "company_to_deal"
                        },
                        {
                            "id": "8330464724",
                            "type": "company_to_deal_unlabeled"
                        },
                        {
                            "id": "8330517224",
                            "type": "company_to_deal_unlabeled"
                        },
                        {
                            "id": "8511793392",
                            "type": "company_to_deal_unlabeled"
                        }
                    ]
                }
            }
        },
        {
            "id": "8109465573",
            "properties": {
                "createdate": "2023-07-20T13:25:52.999Z",
                "domain": "marvel.com",
                "hs_lastmodifieddate": "2023-08-21T03:30:57.721Z",
                "hs_object_id": "8109465573",
                "name": "Marvel"
            },
            "createdAt": "2023-07-20T13:25:52.999Z",
            "updatedAt": "2023-08-21T03:30:57.721Z",
            "archived": false
        }
    ],
    "paging": {
        "next": {
            "after": "8239956985",
            "link": "https://api.hubapi.com/crm/v3/objects/companies?associations=deals&after=8239956985"
        }
    }
}

 

Notice in the above request there is an associations object containing "deals" with an array of results. You can then use the ID of each deal to retrieve specific pieces of information i.e the name, amount, stage etc...

 

I hope this helps.

 

 

View solution in original post

0 Upvotes
2 Replies 2
newera
Member

Get deals based on company id

SOLVE

Thanks @coldrickjack that worked 

0 Upvotes
coldrickjack
Solution
Guide

Get deals based on company id

SOLVE

Hi @newera,

 

CRM records are associated to one another by a special type of object known as an "Association" object. There is even a dedicated suite of endpoints to interact with this object type (create, read, update and delete associations). 

 

When using the CRM APIs you can include "associations" parameter in your request and specify the name of the associated objects you wish to retrieve. For instance the request below will retrieve all of the companies and any IDs of associated deals.

 

GET https://api.hubapi.com/crm/v3/objects/companies?associations=deals
RESPONSE
{
    "results": [
        {
            "id": "8139119856",
            "properties": {
                "createdate": "2023-07-26T12:30:48.856Z",
                "domain": "nintendo.com",
                "hs_lastmodifieddate": "2023-08-28T13:51:39.121Z",
                "hs_object_id": "8139119856",
                "name": "Nintendo"
            },
            "createdAt": "2023-07-26T12:30:48.856Z",
            "updatedAt": "2023-08-28T13:51:39.121Z",
            "archived": false,
            "associations": {
                "deals": {
                    "results": [
                        {
                            "id": "8330464724",
                            "type": "company_to_deal"
                        },
                        {
                            "id": "8330517224",
                            "type": "company_to_deal"
                        },
                        {
                            "id": "8511793392",
                            "type": "company_to_deal"
                        },
                        {
                            "id": "8330464724",
                            "type": "company_to_deal_unlabeled"
                        },
                        {
                            "id": "8330517224",
                            "type": "company_to_deal_unlabeled"
                        },
                        {
                            "id": "8511793392",
                            "type": "company_to_deal_unlabeled"
                        }
                    ]
                }
            }
        },
        {
            "id": "8109465573",
            "properties": {
                "createdate": "2023-07-20T13:25:52.999Z",
                "domain": "marvel.com",
                "hs_lastmodifieddate": "2023-08-21T03:30:57.721Z",
                "hs_object_id": "8109465573",
                "name": "Marvel"
            },
            "createdAt": "2023-07-20T13:25:52.999Z",
            "updatedAt": "2023-08-21T03:30:57.721Z",
            "archived": false
        }
    ],
    "paging": {
        "next": {
            "after": "8239956985",
            "link": "https://api.hubapi.com/crm/v3/objects/companies?associations=deals&after=8239956985"
        }
    }
}

 

Notice in the above request there is an associations object containing "deals" with an array of results. You can then use the ID of each deal to retrieve specific pieces of information i.e the name, amount, stage etc...

 

I hope this helps.

 

 

0 Upvotes