fastify-xhubspot
contacts.getById / contacts.getByEmail
Fetch a HubSpot contact by internal ID or by email address.
contacts.getById / contacts.getByEmail
Fetch a single HubSpot contact by its internal ID or by email address.
Signatures
fastify.contacts.getById(
contactId: string,
properties?: string[]
): Promise<{ id: string; properties: Record<string, string>; createdAt: string; updatedAt: string }>
fastify.contacts.getByEmail(
email: string,
properties?: string[]
): Promise<{ id: string; properties: Record<string, string>; email: string }>
Params
getById
| Name | Type | Required | Description |
|---|---|---|---|
contactId | string | Yes | HubSpot internal contact ID. |
properties | string[] | No | Extra property names to include in the response. |
getByEmail
| Name | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Email address to look up. |
properties | string[] | No | Extra property names to include in the response. |
Returns
getById
| Field | Type | Description |
|---|---|---|
id | string | HubSpot contact ID. |
properties | object | Stored properties for the contact. |
createdAt | string | ISO 8601 creation timestamp. |
updatedAt | string | ISO 8601 last-updated timestamp. |
getByEmail
| Field | Type | Description |
|---|---|---|
id | string | HubSpot contact ID. |
properties | object | Stored properties for the contact. |
email | string | The email address used to look up the contact. |
Throws
[xHubspot] contacts.getById requires a contactId— ifcontactIdis falsy.[xHubspot] contacts.getByEmail requires an email string— ifemailis missing or not a string.- Re-throws the HubSpot API error (e.g., 404 if the contact doesn't exist).
Examples
getById — fetch with extra properties
const contact = await fastify.contacts.getById("12345", ["phone", "company"]);
console.log(contact.properties.phone);
getByEmail — look up at login time
fastify.post("/login", async (request, reply) => {
const { email } = request.body;
let contact;
try {
contact = await fastify.contacts.getByEmail(email);
} catch (err) {
if (err.code === 404) {
return reply.code(404).send({ error: "Contact not found" });
}
throw err;
}
return { contactId: contact.id, name: contact.properties.firstname };
});
See also
- contacts.create — create a contact if it doesn't exist
- contacts.update — update properties after fetching
- contacts.search — search by any property, not just email
AI Context
package: "@xenterprises/fastify-xhubspot"
methods: fastify.contacts.getById(id) | fastify.contacts.getByEmail(email)
use-when: Fetch a single HubSpot contact by ID or email address
returns: { id, properties }
