Efficient way of getting deals and companies

Hi,
I have a senario were I want to get deals between two dates and for that I’m using the

https://api.hubapi.com/crm/v3/objects/deals/search api

and then I want to get the company for that deal.
But the thing is there can be a lot of deals, let’s say 5000 deals, I then need to first make a api call to

https://api.hubapi.com/crm/v3/objects/deals/${deal.id}/associations/company to get the companyId and then I need to make and api call to

https://api.hubapi.com/crm/v3/objects/companies/${companyId} to get the company details.
but I think that takes too long to do that. Is there a faster/better way to do the that. As I need both the deal and the company information.
or even better search companies based on their domain and get their deals
Thanks in advance

Get your deal and then get the companies using batch processing api call instead of single api calls.

/crm/v3/objects/companies/batch/read

Get the accociations in batches as well - you can only do 100 at a time in batches but way better than singularly.

There is also another way to get more at once using GraphQL instead of the search function - but I can’t advise on that as I have not used it yet.

@dsmarion how do I get the accociations in batches? I thought that was not possible

@newera

/crm/v4/associations/{fromObjectType}/{toObjectType}/batch/read

@dsmarion but that does not return any data just some status etc

@newera - No, it returns all the associations requested. You can then use those object IDs to batch read the data you really want.

For example, I will use this for getting all the line items of a batch of deals. In this example I only sent an array of 3 deal IDs but usually I send 50-100. Then I get back all of the line-item associations for those deals, which I can then gather up to batch read the line item data (100 at a time).

Here is the data I got back from the associations batch read for my 3 deals I requested (input IDs). I will then use that data to gather up the resulting toObjectID values into an array to call the batch read for line items to get the actual line item data.

Hope this makes more sense now.

HTTP 200

{
“status”: “COMPLETE”,
“results”: [
{
“from”: {
“id”: “16174181965”
},
“to”: [
{
“toObjectId”: 8112087555,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 8139460147,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 8139462778,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
}
]
},
{
“from”: {
“id”: “13909957168”
},
“to”: [
{
“toObjectId”: 6236416028,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6236416029,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6236416030,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6236416031,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6236416032,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6236416033,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6236416034,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6236416035,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
}
]
},
{
“from”: {
“id”: “15122393088”
},
“to”: [
{
“toObjectId”: 6826785955,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6827757969,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6852615703,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 6853959255,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 7791156264,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
},
{
“toObjectId”: 7791193741,
“associationTypes”: [
{
“category”: “HUBSPOT_DEFINED”,
“typeId”: 19,
“label”: null
}
]
}
]
}
],
“startedAt”: “2024-02-10T16:46:49.526Z”,
“completedAt”: “2024-02-10T16:46:49.542Z”
}

@newera- sorry, I have tried responding with an example but it hasn’t gone through for some reason - I ended of DMing the sample to you because it wouldn’t send here for whatever reason.

@newera - No, it returns all the associations requested. You can then use those object IDs to batch read the data you really want.

For example, I will use this for getting all the line items of a batch of deals. In this example I only sent an array of 3 deal IDs but usually I send 50-100. Then I get back all of the line-item associations for those deals, which I can then gather up to batch read the line item data (100 at a time).

Here is the data I got back from the associations batch read for my 3 deals I requested (input IDs). I will then use that data to gather up the resulting toObjectID values into an array to call the batch read for line items to get the actual line item data.

Hope this makes more sense now.