Companies Batch Read by unique property

On request

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

{
 "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?

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 :thinking:

This is the body that I sent

{
 "inputs":[
 {"id":"toot"},
 {"id":"toots"}
 ],
 "properties":["unique_company_property", "name"],
 "idProperty":"unique_toot"
}

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

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

I received an invalid json error

@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:

or cURL (to be sure about the headers):

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"
}'

@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,

@dennisedson

You are right. This is a response from property:

{
 "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?

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)

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.

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

@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)

@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.

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

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

Hope that helps!

@tominal but then I need the id

Request:

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:

{
 "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?

@AMilenko ,

Apologies, but I am not 100% following.

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

@dennisedson forget. My mistake

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

Hubspot API Doc so scarce :disappointed_face: 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)

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.