Skip to content

Batch Operations

Batch methods operate on up to 100 items per request. When you pass more than 100 items, the package automatically chunks them into multiple requests and merges the results.

Batch Events

Batch operations fire their own lifecycle events (BatchCreating, BatchCreated, etc.) instead of per-model events. Before-events are cancellable, and listeners can filter individual records. See the Events page for details.

Batch Create

php
use Rollogi\LaravelHubspot\Crm\Contact;

$contacts = Contact::createMany([
    ['firstname' => 'John', 'email' => 'john@example.com'],
    ['firstname' => 'Jane', 'email' => 'jane@example.com'],
]);

// Returns a Collection of hydrated Contact models
$contacts->each(fn (Contact $contact) => echo $contact->id);

Batch Update

Each record must include an id key alongside the properties to update:

php
use Rollogi\LaravelHubspot\Crm\Contact;

$contacts = Contact::updateMany([
    ['id' => '123', 'firstname' => 'Updated John'],
    ['id' => '456', 'firstname' => 'Updated Jane'],
]);

Batch Upsert

Create or update records based on a unique identifier property. Each record must include the idProperty field value:

php
use Rollogi\LaravelHubspot\Crm\Contact;

$contacts = Contact::upsertMany([
    ['email' => 'john@example.com', 'firstname' => 'John'],
    ['email' => 'jane@example.com', 'firstname' => 'Jane'],
], idProperty: 'email');

Batch Delete

php
use Rollogi\LaravelHubspot\Crm\Contact;

Contact::deleteMany(['123', '456', '789']);

Auto-Chunking

All batch methods automatically chunk inputs into groups of 100 (HubSpot's per-request limit):

php
use Rollogi\LaravelHubspot\Crm\Contact;

// 250 records → 3 API requests (100 + 100 + 50), results merged
$contacts = Contact::createMany($largeArray);