fastify-xhubspot
contacts.create
Create a new HubSpot contact from a properties object.
contacts.create
Create a new contact in HubSpot CRM.
Signature
fastify.contacts.create(contactData: Record<string, string>): Promise<{
id: string;
properties: Record<string, string>;
createdAt: string;
}>
Params
| Name | Type | Required | Description |
|---|---|---|---|
contactData | object | Yes | Map of HubSpot property names to values. Common properties: email, firstname, lastname, phone, company. |
Returns
| Field | Type | Description |
|---|---|---|
id | string | HubSpot contact ID. |
properties | object | All stored properties for the contact. |
createdAt | string | ISO 8601 creation timestamp. |
Throws
[xHubspot] contacts.create requires a contactData object— ifcontactDatais missing or not an object.- Re-throws the HubSpot API error on failure (e.g., duplicate email).
Examples
Basic — create a contact
const contact = await fastify.contacts.create({
email: "alice@example.com",
firstname: "Alice",
lastname: "Smith",
phone: "+15551234567",
});
console.log(contact.id); // "12345"
console.log(contact.properties); // { email: "alice@example.com", ... }
Realistic — create on form submission
fastify.post("/signup", async (request, reply) => {
const { email, name, company } = request.body;
const [firstname, ...rest] = name.split(" ");
const contact = await fastify.contacts.create({
email,
firstname,
lastname: rest.join(" "),
company,
hs_lead_status: "NEW",
});
return reply.code(201).send({ contactId: contact.id });
});
See also
- contacts.update — update properties on an existing contact
- contacts.getById — fetch the contact after creation
- contacts.batchCreate — create multiple contacts at once
AI Context
package: "@xenterprises/fastify-xhubspot"
method: fastify.contacts.create(contactData)
use-when: Create a new HubSpot contact — pass a map of HubSpot property names to values (email, firstname, lastname, phone, company)
returns: { id, properties, createdAt }
