Hi all,
I try to batch read custom objects associated to a given contact id.
I have a list of ids (the custom object ids) and I call
this.hubspotClient.crm.objects.batchApi.read(objectTypeId, { inputs: [ {id: "123"} ], properties: ["name", "status"], propertiesWithHistory: []})
When I call the api I get the followin error:
{ status: "error", message: "Invalid input JSON on line 1, column 245. Some required fields were not set: [id]", correlationId: "1a1a2893-e2cf-4f8a-8ac5-22f8aa763b55", category: "VALIDATION_ERROR",}
I didn’t find any details in the documentation about this sort of error, would love to get some help to make better use of the api
Hey, @ShirinRo
Welcome to our community! Thanks for your question. Your post didn’t indicate if you’ve tried this, but one troubleshooting step is performing a read operation with a single ID outside the batch process. This helps determine whether the problem lies specifically within the batch operation or the read operation in general.
Best,
Jaycee
Hi @Jaycee_Lewis
Thank you for the prompt respones.
I have performed a read operation on a single object, and it works fine.
I want to use the batch read api for performance reasons, because currently my code looks somewhat like this:
const objectIds = this.getObjectIdsToRead();arr = []for (const id of objectIds) { const object = await this.hubspotClient.crm.objects.basicApi.getById( objectTypeId, id, properties: ["name", "status"], ); arr.push(object)}return arr
and it works but I want to change it to
const objectIds = this.getObjectIdsToRead().map((id) => { id });return this.hubspotClient.crm.objects.batchApi.read(objectTypeId, { inputs: objectIds, properties: ["name", "status"], propertiesWithHistory: []})
Hey @ShirinRo
Closing the loop here in case others come across this question. I am unable to reproduce your error. If we step back and test using the on-page example from the dev doc, we can test the endpoint and basic syntax.
Here’s my example —
Request:
curl --request POST \
--url 'https://api.hubapi.com/crm/v3/objects/contacts/batch/read?archived=false' \
--header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'content-type: application/json' \
--data '{
"propertiesWithHistory": [
"hs_lead_status"
],
"inputs": [
{
"id": "901"
}
],
"properties": [
"name",
"status"
]
}'
Response:
HTTP 200
{
"status": "COMPLETE",
"results": [
{
"id": "901",
"properties": {
"createdate": "2022-11-03T21:42:31.255Z",
"hs_object_id": "901",
"lastmodifieddate": "2024-05-22T00:51:03.167Z",
"name": null,
"status": "Nope"
},
"propertiesWithHistory": {
"hs_lead_status": [
{
"value": "Follow Up",
"timestamp": "2024-05-22T00:34:16.066Z",
"sourceType": "INTEGRATION",
"sourceId": "959085"
}
]
},
"createdAt": "2022-11-03T21:42:31.255Z",
"updatedAt": "2024-05-22T00:51:03.167Z",
"archived": false
}
],
"startedAt": "2024-05-22T00:54:47.275Z",
"completedAt": "2024-05-22T00:54:47.324Z"
}
I hope this helps! — Jaycee
@Jaycee_Lewis Hi, can I get an update here? this still doesn’t work