I tried asking this on the hubspot community but my question there gets automatically marked as spam, so I'll try my luck here.
I'm using the @hubspot/api-client v8.1.0 package for NodeJS. Here is a piece of code I'm using to test getting contacts associated to deals:
const deals = await Api.dealsByStage('Grundbuchdaten Hinzugefügt', 1000, 100, _ => true);
const contacts: Record<string, any> = {};
for (let deal of deals) {
console.log(`Processing deal ${deal.id}`);
const dealContacts = await Api.client.crm.deals.associationsApi.getAll(deal.id, 'contact');
contacts[deal.id] = dealContacts.results;
}
await fs.writeFile('./sample.json', JSON.stringify(contacts, null, 2));
The Api.dealsByStage
function on top is a function I wrote that gets a list of deals (in this case it gets the top 1000 deals). That works fine because I can see the for
loop looping through each deal ID, and also I already use the function on other parts of the code with no issues.
But the call to associationsApi.getAll
is the one acting weird. I do get a list of either 0, 1 or 2 empty objects (with no properties, not even the contact ID). If I was getting an empty list of contacts I guess it could be that the deals have no associated contacts, but I'm actually getting something back. Here are a few of the results I get:
"5336323558": [],
"5336234188": [
{}
],
"5336291063": [
{},
{}
],
"5336870390": [],
I also tried using the "contacs" (with an "s") object type but got the same results. Am I using the wrong API or doing something else wrong?