Inconsistent contact property updates using HubSpot Batch API

I’m having trouble with the HubSpot Batch API for updating contact properties. I’m using a batch size of 50 contacts but I’m seeing weird results. Some properties update fine but others don’t change at all.

I know HubSpot doesn’t update the “update date” if the new value is the same as the old one. But in my case the new values are different so they should all update. Here’s a simplified version of my code:

function updateContactBatch($batchData) {
    $updates = [];
    foreach ($batchData as $data) {
        $contact = findContact($data['email']);
        if (!$contact) continue;

        $props = [
            'prop_1' => $data['val_1'],
            'prop_2' => $data['val_2'],
            'prop_3' => $data['val_3'],
            'prop_4' => $data['val_4'],
            'prop_5' => $data['val_5'],
        ];

        $updates[] = new ContactUpdate([
            'id' => $contact->id,
            'properties' => $props
        ]);

        pause(1);
    }

    if ($updates) {
        $batchUpdate = new BatchUpdate(['updates' => $updates]);
        pause(40);
        sendBatchUpdate($batchUpdate);
    }
}

Any ideas why some properties aren’t updating? I’m stumped and could really use some help. Thanks!

I’ve encountered similar issues with the HubSpot Batch API before. One thing that helped me was implementing more robust error handling and logging. Sometimes, the API can silently fail for certain properties without throwing an obvious error.

Try adding a try-catch block around your sendBatchUpdate() call and log any exceptions. Also, consider implementing a retry mechanism for failed updates. I found that occasionally, retrying a failed batch would succeed on the second or third attempt.

Another thing to check is the property definitions in HubSpot. Make sure all the properties you’re trying to update are actually defined and have the correct field types. I once spent hours debugging a similar issue only to realize one of my properties wasn’t properly set up in HubSpot.

Lastly, double-check your data types. HubSpot can be picky about the format of certain fields like dates or numbers. If the data type doesn’t match exactly what HubSpot expects, it might silently reject the update for that specific property.

Hope this helps point you in the right direction!