fastify-xhubspot
customObjects.batchCreate
Create multiple HubSpot custom object records in a single API call.
customObjects.batchCreate
Create multiple records for a given HubSpot custom object type in a single API call. Useful for bulk imports or syncing data from an external system.
Signature
fastify.customObjects.batchCreate(
objectType: string,
objects: Array<Record<string, string>>
): Promise<Array<{ id: string; properties: Record<string, string> }>>
Params
| Name | Type | Required | Description |
|---|---|---|---|
objectType | string | Yes | The custom object type name or ID (e.g., "subscriptions", "2-12345"). |
objects | Array<object> | Yes | Non-empty array of property maps. Each element follows the same shape as customObjects.create. |
Returns
Array of { id, properties } for each created record.
Throws
[xHubspot] customObjects.batchCreate requires an objectType— ifobjectTypeis missing.[xHubspot] customObjects.batchCreate requires a non-empty array— ifobjectsis empty or not an array.- Re-throws the HubSpot API error on network failure after logging via
fastify.log.error.
Examples
Basic — create multiple subscription records
const created = await fastify.customObjects.batchCreate("subscriptions", [
{ plan_name: "Starter", billing_cycle: "monthly", status: "active" },
{ plan_name: "Pro", billing_cycle: "annual", status: "active" },
]);
console.log(`Created ${created.length} subscriptions`);
Realistic — bulk import from a CSV migration
fastify.post("/import/subscriptions", async (request, reply) => {
const rows = parseCsv(request.body.csv);
const records = rows.map(row => ({
plan_name: row.plan,
billing_cycle: row.cycle,
status: row.status,
stripe_subscription_id: row.stripe_id,
}));
const created = await fastify.customObjects.batchCreate(
"subscriptions",
records
);
return reply.send({ imported: created.length });
});
See also
- customObjects.create — create a single record
- customObjects.list — list records after import
- customObjects.associate — link created records to contacts or companies
AI Context
package: "@xenterprises/fastify-xhubspot"
method: fastify.customObjects.batchCreate(objectTypeId, records)
use-when: Bulk create custom object records in one API call
returns: { results }
