X Enterprises
fastify-xhubspot

companies.getById / companies.getByDomain

Fetch a HubSpot company by internal ID or by domain.

companies.getById / companies.getByDomain

Fetch a single HubSpot company by its internal ID or by domain name.

Signatures

fastify.companies.getById(
  companyId: string,
  properties?: string[]
): Promise<{ id: string; properties: Record<string, string> }>

fastify.companies.getByDomain(
  domain: string,
  properties?: string[]
): Promise<{ id: string; properties: Record<string, string> }>

Params

getById

NameTypeRequiredDescription
companyIdstringYesHubSpot internal company ID.
propertiesstring[]NoAdditional property names to include.

getByDomain

NameTypeRequiredDescription
domainstringYesCompany website domain (e.g., "acme.com").
propertiesstring[]NoAdditional property names to include.

Returns

Both return { id, properties }.

Throws

  • [xHubspot] companies.getById requires a companyId — if companyId is falsy.
  • [xHubspot] companies.getByDomain requires a domain string — if domain is missing or not a string.
  • [xHubspot] Company not found for domain: <domain> (status 404) — if getByDomain finds no match.
  • Re-throws HubSpot API errors.

Examples

getById

const company = await fastify.companies.getById("98765", ["phone", "city"]);
console.log(company.properties.name);

getByDomain — enrich a contact's company on sign-up

fastify.post("/onboard", async (request, reply) => {
  const { email } = request.body;
  const [, domain] = email.split("@");

  let company = null;
  try {
    company = await fastify.companies.getByDomain(domain);
  } catch (err) {
    if (err.status !== 404) throw err;
  }

  return { companyId: company?.id ?? null };
});

See also

AI Context

package: "@xenterprises/fastify-xhubspot"
methods: fastify.companies.getById(id) | fastify.companies.getByDomain(domain)
use-when: Fetch a HubSpot company by ID or website domain
returns: { id, properties }
Copyright © 2026