# Getting associated company ID from Tasks Batch Read API

**URL:** <https://community.hubspot.com/t/getting-associated-company-id-from-tasks-batch-read-api/63566>\
**Category:** APIs & Integrations\
**Tags:** companies\
**Created:** [August 23, 2022, 4:39pm UTC](https://community.hubspot.com/t/getting-associated-company-id-from-tasks-batch-read-api/63566 "2022-08-23T16:39:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alehti](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alehti/32/196170_2.png) [@alehti](https://community.hubspot.com/u/alehti)\
**Post date:** [August 23, 2022, 4:39pm UTC](https://community.hubspot.com/t/getting-associated-company-id-from-tasks-batch-read-api/63566/1 "2022-08-23T16:39:00Z")

</div>

Hey!

My end goal is to get a list of companies that have (any) completed tasks within a given time period. This turned out to be trickier than I expected.

I’d want to avoid looping single companies and taks, because the amount of calls may be very high. I have tried several approaches but all seem to stop to the limitations in search/batch APIs.

**Approach #1**

1. Search tasks that have been completed within a given timeframe. Return associated company IDs.

2. Batch read associated companies by returned company IDs.

Problem:

Associated company IDs cannot be retrieved from Search Tasks endpoint. Apparently I would have to check associations per task, which I wouldn’t want to do.

**Approach #2:**

1. Search tasks that have been completed within a given timeframe.

2. Use Associations API to batch read all associated companies by returned task IDs. Return company IDs.

3. Batch read associated companies by returned company IDs.

Problem:

I haven’t found a way to batch read associations from tasks to companies. Is there a way to do it?

Or is there a completely different approach that would take me to my goal, without looping through objects?

Thanks for your help!

##### EDIT 1 #####

Was able to find an endpoint that returns a list of associations between given Task IDs and companies. However, I could find a way to do it by using V4 API, like documented [here.](https://developers.hubspot.com/docs/api/crm/associations) An example for V4 would be golden.

I used the Python library hubspot-api-client that has the

hubspot.crm.associations.batch\_api.read() method for which you can pass a list of IDs as an input.

```lia-code-sample
from hubspot import HubSpot
from hubspot.crm.associations import BatchInputPublicObjectId
params = {
 'from_object_type': 'tasks',
 'to_object_type': 'companies',
 'batch_input_public_object_id': BatchInputPublicObjectId(
 inputs=[{"id": 1, "id": 2}]
 )
}
hs = HubSpot() # Use your access token
hs.crm.associations.batch_api.read(**params)

```

##### EDIT 2 #####

Next problem: I cannot get a list of companies with the returned company IDs by using Company Read Batch endpoint. It’s probably because company ID is not a unique property (it has has\_unique\_value as False). Why on earth is it so?

This starts to seem like a huge overkill for such a simple task. I can’t be the only one who wants to get a list of tasks, with the associated companies…

##### EDIT 3 #####

Okay, got the thing done by using Company Search endpoint, searching by company IDs. Would’ve thought that batch API was created for something like “get companies by IDs”, but I guess I was wrong.

So eventually this turned out to be a wish to return associated company IDs (if requested), when searching for Tasks.

---

<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:** [August 23, 2022, 10:51pm UTC](https://community.hubspot.com/t/getting-associated-company-id-from-tasks-batch-read-api/63566/2 "2022-08-23T22:51:40Z")

</div>

Hey, @alehti 👋 Thanks for sharing both your problem and the eventual solution 🙌 — Jaycee

---

<div class="post-metadata">

**Author:** ![Yel-o](https://avatars.discourse-cdn.com/v4/letter/y/958977/32.png) [@Yel-o](https://community.hubspot.com/u/Yel-o)\
**Post date:** [October 5, 2022, 9:46pm UTC](https://community.hubspot.com/t/getting-associated-company-id-from-tasks-batch-read-api/63566/3 "2022-10-05T21:46:32Z")

</div>

I’m looking to do the same thing but will be using Postman. From what I understand, instead of doing a POST search on tasks, you did a POST search through the companies?
