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

NameTypeRequiredDescription
contactIdstringYesHubSpot internal contact ID.
propertiesstring[]NoExtra property names to include in the response.

getByEmail

NameTypeRequiredDescription
emailstringYesEmail address to look up.
propertiesstring[]NoExtra property names to include in the response.

Returns

getById

FieldTypeDescription
idstringHubSpot contact ID.
propertiesobjectStored properties for the contact.
createdAtstringISO 8601 creation timestamp.
updatedAtstringISO 8601 last-updated timestamp.

getByEmail

FieldTypeDescription
idstringHubSpot contact ID.
propertiesobjectStored properties for the contact.
emailstringThe email address used to look up the contact.

Throws

  • [xHubspot] contacts.getById requires a contactId — if contactId is falsy.
  • [xHubspot] contacts.getByEmail requires an email string — if email is 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

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 }
Copyright © 2026