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
Overall, I think the approach you've outlined will generally work well. However, you may want to consider some additional cases.
For scenario 1, as long as you know for sure those specific records existed previously in the given HubSpot Portal, then your suggested approach will work in the majority of cases. However, you may want to consider the possibility that these deleted records could be "restored" at a later date. When deleting a record via HubSpot's UI, the user is given 2 choices: [1] Restorable Delete (i.e. record can be restored up to 90 days after deletion), or [2] Permanent Delete (gone forever, not restorable). You can verify which case is true via API by using the "archived" query string parameter (available on single and batch operations). If the record is returned successfully and is marked as "archived": true, then there remains a chance this record could be restored. However, if the record is not found, then it can no longer be restored. See example below for how to include the "archived" query string parameter in your Get Batch Contacts request.
For scenario 2, I would request the "hs_calculated_merged_vids" and "hs_merged_object_ids" properties be returned from your Get Batch Contacts request. This would help to confirm which records have been merged and all the IDs in play. For example:
Overall, I think the approach you've outlined will generally work well. However, you may want to consider some additional cases.
For scenario 1, as long as you know for sure those specific records existed previously in the given HubSpot Portal, then your suggested approach will work in the majority of cases. However, you may want to consider the possibility that these deleted records could be "restored" at a later date. When deleting a record via HubSpot's UI, the user is given 2 choices: [1] Restorable Delete (i.e. record can be restored up to 90 days after deletion), or [2] Permanent Delete (gone forever, not restorable). You can verify which case is true via API by using the "archived" query string parameter (available on single and batch operations). If the record is returned successfully and is marked as "archived": true, then there remains a chance this record could be restored. However, if the record is not found, then it can no longer be restored. See example below for how to include the "archived" query string parameter in your Get Batch Contacts request.
For scenario 2, I would request the "hs_calculated_merged_vids" and "hs_merged_object_ids" properties be returned from your Get Batch Contacts request. This would help to confirm which records have been merged and all the IDs in play. For example:
Hi @LZhao👋 Thanks for your detailed post. That is always appreciated. I'd like to invite some of our community members to the conversation to share their thoughts — hey @zach_threadint@evaldas@TomM2@Bryantworks, do you have any relevant experience and wisdom you can share with @LZhao?