APIs & Integrations

LZhao
Participant

Question about batch read API

Hi,
I am using the /crm/v3/objects/$objType/batch/read POST API to detect deleted or merged objects on HubSpot, but I have a few questions about its behavior to ensure I use it correctly and avoid unintended deletions in my system.
Scenario 1: Deleted Objects
When an object is deleted on HubSpot, the API returns the following response:
{
"results": [],
"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": [
"8380080352",
"8144745976",
"7440157923"
]
}
}
]
}
In this case, if category is OBJECT_NOT_FOUND, I can extract the ids from the errors.context.ids array and handle them as deleted objects in my system.


Scenario 2: Merged Objects
Sometimes, contacts in HubSpot are merged. In such cases, the API can return the following response:
{
"results": [
{
"id": "84805801",
"properties": {
"email": "mary.miller@usfoods.com",
"createdate": "2020-03-03T20:18:42.589Z",
"firstname": "Mary",
"hs_object_id": "84805801",
"lastname": "Miller",
"lastmodifieddate": "2024-08-10T23:13:12.293Z"
},
"createdAt": "2020-03-03T20:18:42.589Z",
"updatedAt": "2024-08-10T23:13:12.293Z"
}
]
}
Here, the id in the response (84805801) is different from the id in my original request (62241). This indicates that the contact was merged. In such cases, I also need to remove this record (62241) from my system.


Questions:
1. Are there other scenarios I should consider to avoid mistakenly deleting or overwriting data in my system?
2. For merged objects, is it safe to assume that if the id in the response differs from the id in my request, the object has been merged, and the new ID should be used?
3. Is there a recommended approach to handle errors and results together to ensure I don’t miss any edge cases?
Any insights or recommendations for using this API correctly would be greatly appreciated, thanks

0 Upvotes
1 Reply 1
Bortami
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Question about batch read API

You can also verify that the records were truly deleted and not an error by passing archived=true in the url.

 

The new Id returned is the new merged record id. All previous records that were merged into that record will be routed to that new id. One thing to watch out for is that it doesn't tell you which companies were merged into it unless you specify the property hs_merged_object_ids and do comparison with it's content. 

0 Upvotes