# Problem when working with data via API

**URL:** <https://community.hubspot.com/t/problem-when-working-with-data-via-api/68457>\
**Category:** APIs & Integrations\
**Tags:** contacts\
**Created:** [November 3, 2022, 9:08am UTC](https://community.hubspot.com/t/problem-when-working-with-data-via-api/68457 "2022-11-03T09:08:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmitryOnCentive](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@dmitryOnCentive](https://community.hubspot.com/u/dmitryOnCentive)\
**Post date:** [November 3, 2022, 9:08am UTC](https://community.hubspot.com/t/problem-when-working-with-data-via-api/68457/1 "2022-11-03T09:08:10Z")

</div>

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:

```lia-code-sample
 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.

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [November 3, 2022, 10:24pm UTC](https://community.hubspot.com/t/problem-when-working-with-data-via-api/68457/2 "2022-11-03T22:24:53Z")

</div>

Hi, @dmitryOnCentive 👋 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

---

<div class="post-metadata">

**Author:** ![dmitryOnCentive](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@dmitryOnCentive](https://community.hubspot.com/u/dmitryOnCentive)\
**Post date:** [November 16, 2022, 2:46pm UTC](https://community.hubspot.com/t/problem-when-working-with-data-via-api/68457/3 "2022-11-16T14:46:13Z")

</div>

Hey [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074) @JBeatty @albertsg, any updates on my issue?
