fastify-xhubspot
customObjects.create
Create a new record for a HubSpot custom object type.
customObjects.create
Create a new record for a given HubSpot custom object type.
Signature
fastify.customObjects.create(
objectType: string,
objectData: Record<string, string>
): Promise<{ id: string; properties: Record<string, string> }>
Params
| Name | Type | Required | Description |
|---|---|---|---|
objectType | string | Yes | The custom object type name or ID (e.g., "pets", "2-12345"). |
objectData | object | Yes | Map of property names to values as defined in the custom object schema. |
Returns
| Field | Type | Description |
|---|---|---|
id | string | HubSpot record ID for the new custom object. |
properties | object | All stored properties for the record. |
Throws
[xHubspot] customObjects.create requires an objectType— ifobjectTypeis missing.[xHubspot] customObjects.create requires an objectData object— ifobjectDatais missing or not an object.- Re-throws the HubSpot API error on network failure after logging via
fastify.log.error.
Examples
Basic — create a "Pet" custom object record
const pet = await fastify.customObjects.create("pets", {
name: "Buddy",
species: "Dog",
breed: "Labrador",
});
console.log(pet.id); // "1001"
Realistic — create a product subscription record on checkout
fastify.post("/subscriptions", async (request, reply) => {
const { planName, billingCycle, contactId } = request.body;
const subscription = await fastify.customObjects.create("subscriptions", {
plan_name: planName,
billing_cycle: billingCycle,
status: "active",
});
await fastify.customObjects.associate(
"subscriptions",
subscription.id,
"contacts",
contactId
);
return reply.code(201).send({ subscriptionId: subscription.id });
});
See also
- customObjects.getById — fetch a record after creation
- customObjects.update — update an existing record
- customObjects.associate — link a custom object record to another CRM object
AI Context
package: "@xenterprises/fastify-xhubspot"
method: fastify.customObjects.create(objectTypeId, properties)
use-when: Create a new HubSpot custom object record
returns: { id, properties }
