X Enterprises
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

NameTypeRequiredDescription
objectTypestringYesThe custom object type name or ID (e.g., "pets", "2-12345").
objectDataobjectYesMap of property names to values as defined in the custom object schema.

Returns

FieldTypeDescription
idstringHubSpot record ID for the new custom object.
propertiesobjectAll stored properties for the record.

Throws

  • [xHubspot] customObjects.create requires an objectType — if objectType is missing.
  • [xHubspot] customObjects.create requires an objectData object — if objectData is 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

AI Context

package: "@xenterprises/fastify-xhubspot"
method: fastify.customObjects.create(objectTypeId, properties)
use-when: Create a new HubSpot custom object record
returns: { id, properties }
Copyright © 2026