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
| Name | Type | Required | Description |
|---|---|---|---|
companyId | string | Yes | HubSpot internal company ID. |
properties | string[] | No | Additional property names to include. |
getByDomain
| Name | Type | Required | Description |
|---|---|---|---|
domain | string | Yes | Company website domain (e.g., "acme.com"). |
properties | string[] | No | Additional property names to include. |
Returns
Both return { id, properties }.
Throws
[xHubspot] companies.getById requires a companyId— ifcompanyIdis falsy.[xHubspot] companies.getByDomain requires a domain string— ifdomainis missing or not a string.[xHubspot] Company not found for domain: <domain>(status 404) — ifgetByDomainfinds 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
- companies.create — create the company if not found
- companies.search — search by any property, not just domain
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 }
