Adding multiple contacts to HubSpot efficiently using API

I’m trying to create several contacts in HubSpot using their API but running into timeout issues. When I loop through my contact data, the script fails after 30 seconds because of execution time limits. Is there a way to create multiple contacts at once instead of one by one?

foreach ($contactList as $contact) {
  $contactData['email'] = $contact['email_address'];
  $contactData['firstname'] = $contact['full_name'];
  $hubspotClient = new HubSpot($credentials->api_token);
  $hubspotClient->contacts()->create_new_contact($contactData);
  $contactInfo = $hubspotClient->contacts()->find_contact_by_email($contact['email_address']);
  $addToList = $hubspotClient->lists()->insert_contact_to_list($contactInfo->vid, $listId);
}

I need a bulk method that can handle multiple contacts without hitting timeout errors. Any suggestions for batch processing with HubSpot API?

The timeout’s happening because you’re spinning up a new HubSpot client for every single contact - that’s killing your performance. I ran into the same thing importing big contact lists. Don’t try processing everything at once. Break your contacts into chunks of 50-100 and run each batch separately with a short delay between them. Gives the server room to breathe and prevents memory crashes. If this is a one-time import, honestly just use HubSpot’s bulk import in their UI - way more reliable than hammering the API. For ongoing syncs, batch API works fine but add proper error handling because one network hiccup can trash your whole batch.

I’ve dealt with this exact problem for years. The real issue isn’t timeouts - it’s building something fragile that breaks every time HubSpot changes.

Skip wrestling with batch APIs and error handling. Automate it properly instead. I built a workflow that watches for new contact data, chunks it automatically, handles HubSpot API calls with retry logic, and manages list assignments without timeout issues.

You just drop contact data somewhere and forget it. No babysitting scripts or partial failures. When HubSpot changes their API, you update the workflow once instead of hunting through code.

I’ve run setups like this for massive imports - thousands of records - with zero manual work. Set it once and it works.

Check out Latenode for this automation: https://latenode.com

You’re getting timeouts because you’re making three API calls per contact AND initializing the client inside your loop. That’s killing your performance. Use HubSpot’s Batch API instead - you can create up to 100 contacts in one request. Move that client initialization outside the loop, prep all your contact data first, then send it all in one batch. You’ll still need separate calls for adding contacts to lists, but you can batch those too once you’ve got the contact IDs. I went from several minutes down to under 10 seconds for 500 contacts doing this. Just watch out for partial failures in the batch response - some contacts might fail validation while others go through fine.

you’re doing way too much work per contact. move that hubspot client outside the loop first - that’s probably half your performance problem right there. also try using array_chunk() to split your contacts into smaller batches of 20-30 and process each batch separately with a sleep() between them. helps avoid hitting rate limits too.

Been working with HubSpot integrations for three years - your timeouts are coming from a couple bottlenecks. You’re creating a new client instance inside every loop iteration, which means unnecessary auth handshakes for each contact. Move that initialization outside the foreach loop. Better yet, ditch the synchronous processing entirely. I queue contact data in Redis, then have a separate worker handle API calls in small batches. Your initial request just queues everything and returns right away - the HubSpot calls run in the background. No more timeouts. Throw in exponential backoff for failed requests and you can resume from where you left off if things break. Way more reliable than cramming everything into one execution.

Your script’s timing out because you’re doing three API calls per contact - create, find, then add to list. I’ve watched this same setup crash with bigger datasets. You’re basically waiting for each contact to finish before starting the next one, which kills performance. Try async processing with cURL multi-handle in PHP instead. Fire off multiple contact creations at once without waiting around. When the batch responses come back, grab the contact IDs straight from the creation response - skip those find_contact_by_email calls completely. That’s just wasted API hits. For adding to lists, collect all your new contact IDs first, then batch those too. I usually run 25-50 contacts at the same time and almost never hit timeouts anymore. Just beef up your error handling since some contacts might fail while others work fine.