X Enterprises
fastify-xhubspot

customObjects.getById

Fetch a single HubSpot custom object record by its ID.

customObjects.getById

Retrieve a single record for a given HubSpot custom object type by its internal ID.

Signature

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

Params

NameTypeRequiredDescription
objectTypestringYesThe custom object type name or ID (e.g., "pets", "2-12345").
objectIdstringYesHubSpot internal record ID to fetch.
propertiesstring[]NoList of property names to include in the response. Defaults to all properties.

Returns

FieldTypeDescription
idstringHubSpot record ID.
propertiesobjectProperty values for the record.

Throws

  • [xHubspot] customObjects.getById requires an objectType — if objectType is missing.
  • [xHubspot] customObjects.getById requires an objectId — if objectId is missing.
  • Re-throws the HubSpot API error on network failure (including 404 not found) after logging via fastify.log.error.

Examples

Basic — fetch a subscription record

const subscription = await fastify.customObjects.getById(
  "subscriptions",
  "1001"
);

console.log(subscription.properties.plan_name); // "Pro"

With a property filter

const pet = await fastify.customObjects.getById(
  "pets",
  "2002",
  ["name", "species", "breed"]
);

Realistic — serve a record via API

fastify.get("/subscriptions/:id", async (request, reply) => {
  const record = await fastify.customObjects.getById(
    "subscriptions",
    request.params.id
  );

  return reply.send(record);
});

See also

AI Context

package: "@xenterprises/fastify-xhubspot"
method: fastify.customObjects.getById(objectTypeId, recordId, options?)
use-when: Fetch a single custom object record by ID
returns: { id, properties }
Copyright © 2026