Problem when working with data via API

Hi, I’m a developer and I’m having a problem when working with data in the hubspot. I am using the official client for node.js. I will try to describe the algorithm of work:

1) create contacts (crm.contacts.batchApi.create)
2) create companies (crm.companies.batchApi.create)
3) create deals (crm.deals.batchApi.create)
4) I aggregate information in order to create associations between entities in the hubspot
5) create associations contact/company, company/deal and contact/deal

Then, I merge the IDs of the existing companies in the hubspot that I have in advance, and the IDs of the newly created companies. I need such a scheme of work, because I can not only invite new clients to the application, but also existing clients to the hubspot too.
Then I use the crm.companies.associationsApi.getAll function to get the company and contact associations. The code is like this:

 const hubspotCompaniesWithContacts = await Promise.all(
 hubspotCompanies.map(async (company) => {
 const { results } = await hubspotClient.crm.companies.associationsApi.getAll(
 company.id,
 HubspotObjectType.contact,
 );

 return { ...company, contactId: results[0]?.id };
 }),
 );

The problem is that for some reason I sometimes can’t get these associations (returns empty “results” array), even if the UI hubspot has this association.
Hope for help. Thanks.

Hi, @dmitryOnCentive :waving_hand: Thanks for the including your details. Hey, @JBeatty @albertsg, do you have any thoughts on how @dmitryOnCentive might approach this part of their project?

Best,

Jaycee

Hey @Jaycee_Lewis @JBeatty @albertsg, any updates on my issue?