# Companies Batch Read by unique property

**URL:** <https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050>\
**Category:** APIs & Integrations\
**Tags:** companies\
**Created:** [April 23, 2021, 10:25am UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050 "2021-04-23T10:25:21Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![AMilenko](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amilenko/32/79091_2.png) [@AMilenko](https://community.hubspot.com/u/AMilenko)\
**Post date:** [April 23, 2021, 10:25am UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/1 "2021-04-23T10:25:21Z")

</div>

On request

```lia-code-sample
curl --location --request POST 'https://api.hubapi.com/crm/v3/objects/companies/batch/read?hapikey= ****' \
--header 'Content-Type: application/json' \
--data-raw '{
 "inputs":[
 {"id":"uniquestring1"},
 {"id":"uniquestring2"},
 ],
 "properties":["unique_company_property", "name"],
 "idProperty":"unique_company_property"
}'

```

where “unique\_company\_property” is a Company Property (string and unique for each company)

I always have a response

```lia-code-sample
{
 "status": "COMPLETE",
 "results": [],
 "numErrors": 1,
 "errors": [
 {
 "status": "error",
 "category": "OBJECT_NOT_FOUND",
 "message": "Could not get some COMPANY objects, they may be deleted or not exist. Check that ids are valid.",
 "context": {
 "ids": [
 "uniquestring1", "uniquestring2"
 ]
 }
 }
 ],
 "startedAt": "2021-04-23T10:23:03.902Z",
 "completedAt": "2021-04-23T10:23:03.923Z"
}

```

But when I search by this property at Dashboard, I found the companies. What might be the reason?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [April 26, 2021, 4:23pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/2 "2021-04-26T16:23:00Z")

</div>

Hey@AMilenko

When I first tried to reproduce your code, I received an error due to the extra comma after **{“id”:“uniquestring2”}**

After correcting that, I was able to successfully get a response with the correct companies 🤔

This is the body that I sent

```lia-code-sample
{
 "inputs":[
 {"id":"toot"},
 {"id":"toots"}
 ],
 "properties":["unique_company_property", "name"],
 "idProperty":"unique_toot"
}

```

@tominal , do you see something that I am missing?

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [April 26, 2021, 4:45pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/3 "2021-04-26T16:45:32Z")

</div>

Looks good!  
To make sure, if you add that comma back, do you get the same error as OP?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [April 26, 2021, 4:54pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/4 "2021-04-26T16:54:18Z")

</div>

I received an invalid json error

---

<div class="post-metadata">

**Author:** ![AMilenko](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amilenko/32/79091_2.png) [@AMilenko](https://community.hubspot.com/u/AMilenko)\
**Post date:** [April 26, 2021, 5:23pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/5 "2021-04-26T17:23:06Z")

</div>

@dennisedson @tominal

Thank you guys. But initialy this is not a problem.

It was a mistake when I describe the issue.

Here the correct example with response:

 ![41611i82550EF0F0EF6727.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/1/5/15f2ff3a5f10155467484901aecae02a9db64120.png)

or cURL (to be sure about the headers):

```lia-code-sample
curl --location --request POST 'https://api.hubapi.com/crm/v3/objects/companies/batch/read?hapikey=blah-blah-blah-blah-blah' \
--header 'Content-Type: application/json' \
--header 'Cookie: __cfduid=d98527fbadd2e4332bf350ad62f9a3da31619079715' \
--data-raw '{
 "inputs":[
 {"id":"gettyimages"}
 ],
 "properties":["image_bank_url_company_property"],
 "idProperty":"image_bank_url_company_property"
}'

```

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [April 26, 2021, 8:12pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/6 "2021-04-26T20:12:57Z")

</div>

@AMilenko ,

Can you confirm that **image\_bank\_url\_company\_property** is a unique property? That is the only thing that I can think is wrong here.

The property should return a field like this:

“hasUniqueValue”: **true** ,

---

<div class="post-metadata">

**Author:** ![AMilenko](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amilenko/32/79091_2.png) [@AMilenko](https://community.hubspot.com/u/AMilenko)\
**Post date:** [April 26, 2021, 8:44pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/7 "2021-04-26T20:44:14Z")

</div>

@dennisedson

You are right. This is a response from property:

```lia-code-sample
{
 "updatedAt": "2021-04-23T10:03:16.579Z",
 "createdAt": "2017-11-02T13:12:44.628Z",
 "name": "image_bank_url_company_property",
 "label": "Image Bank URL - Company Property",
 "type": "string",
 "fieldType": "text",
 "description": "Pickit Business Company URL",
 "groupName": "companyinformation",
 "options": [],
 "createdUserId": "3028602",
 "updatedUserId": "5385873",
 "displayOrder": -1,
 "calculated": false,
 "externalOptions": false,
 "archived": false,
 "hasUniqueValue": false,
 "hidden": false,
 "showCurrencySymbol": false,
 "modificationMetadata": {
 "archivable": true,
 "readOnlyDefinition": false,
 "readOnlyValue": false
 },
 "formField": true
}

```

Not a unique values.

And I know why. I have many companies where we don’t have any value (empty) for that property. Does it matter?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [April 26, 2021, 8:50pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/8 "2021-04-26T20:50:45Z")

</div>

in this case, yes. maybe you can use the search endpoints and filter by that property (responding via phone so don’t have a link to provide)

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [April 26, 2021, 8:14pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/9 "2021-04-26T20:14:13Z")

</div>

Ah I see what it is. You need to pass in the actual ID of the company record. You’re passing in a string of what I’m assuming is the title of the record.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [April 26, 2021, 8:16pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/10 "2021-04-26T20:16:07Z")

</div>

I was under the impression that the idea was to get the records by a unique property, in this case **image\_bank\_url\_company\_property** which is completely valid if that property has been to be unique

---

<div class="post-metadata">

**Author:** ![AMilenko](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amilenko/32/79091_2.png) [@AMilenko](https://community.hubspot.com/u/AMilenko)\
**Post date:** [April 26, 2021, 8:54pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/11 "2021-04-26T20:54:28Z")

</div>

@dennisedson You were right.

The idea was to get existed companies by the property to avoid doubles.  
I.e., it helps me to accurate Company ID (if someone removes the company at Hubspot, then create the new one somehow)

---

<div class="post-metadata">

**Author:** ![AMilenko](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amilenko/32/79091_2.png) [@AMilenko](https://community.hubspot.com/u/AMilenko)\
**Post date:** [April 26, 2021, 8:51pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/12 "2021-04-26T20:51:01Z")

</div>

@tominal that was a thought.

Before creating the new company record, check if we already have the record with a unique string property, not the actual ID.

Why batch read instead of search?

Since I want to create ten new companies and I want to check all that companies with the one request.

As far as I remember, with search I might check only 3 companies per request.

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [April 26, 2021, 8:55pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/13 "2021-04-26T20:55:57Z")

</div>

Batch read would be better in that use case then. Your input array looks incorrect though. You must specify:

```auto
"inputs": [
	{
		"properties": {
			"image_bank_url_company_property": "something"
		}
	}
]

```

Hope that helps!

---

<div class="post-metadata">

**Author:** ![AMilenko](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amilenko/32/79091_2.png) [@AMilenko](https://community.hubspot.com/u/AMilenko)\
**Post date:** [April 26, 2021, 9:03pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/14 "2021-04-26T21:03:16Z")

</div>

@tominal but then I need the id

Request:

```lia-code-sample
curl --location --request POST 'https://api.hubapi.com/crm/v3/objects/companies/batch/read?hapikey=123' \
--header 'Content-Type: application/json' \
--header 'Cookie: __cfduid=d98527fbadd2e4332bf350ad62f9a3da31619079715' \
--data-raw '{
 "inputs":[
 {
 "properties": {
 "image_bank_url_company_property": "gettyimages"
 }
 }
 ]
}'

```

Response:

```lia-code-sample
{
 "status": "error",
 "message": "Invalid input JSON on line 7, column 9: Cannot build SimplePublicObjectId, some of required attributes are not set [id]",
 "correlationId": "1d566c18-cba2-42c0-bbbb-2feabd922b84"
}

```

Or I need to use another endpoint?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [April 27, 2021, 2:20pm UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/15 "2021-04-27T14:20:10Z")

</div>

@AMilenko ,

Apologies, but I am not 100% following.

Maybe I am blind, but where is the 3 company limit?

---

<div class="post-metadata">

**Author:** ![AMilenko](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amilenko/32/79091_2.png) [@AMilenko](https://community.hubspot.com/u/AMilenko)\
**Post date:** [April 28, 2021, 5:33am UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/16 "2021-04-28T05:33:37Z")

</div>

@dennisedson forget. My mistake

it was a filter option for search. Not more than 3 filters per filterGroup.

Hubspot API Doc so scarce 😞 I.e., how I might search by company property for many values with OR?

i.e. Find all companies where “image\_bank\_url\_company\_property” is slug1 or slug2 or slug3 or slug4.

I did small research and find that Hubspot Dashboard using value: “slug1 or slug2 or slug3 or slug4”. But this trick doesnt work for search. And I still have no idea about the correct way of searching companies by multiple values of the one property (using API ofc)

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [April 27, 2021, 1:03am UTC](https://community.hubspot.com/t/companies-batch-read-by-unique-property/36050/17 "2021-04-27T01:03:42Z")

</div>

My apologies, the documentation states that this endpoint will “read a batch of companies by internal ID, or unique property values.” So to Dennis’ point, you will have to set that property as unique. I have not worked with this endpoint in this manner so this will be up to you. You may have to store the company IDs of your records and then use them with this endpoint before calling it.  
Hope that helps.
