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
| Name | Type | Required | Description |
|---|---|---|---|
objectType | string | Yes | The custom object type name or ID (e.g., "pets", "2-12345"). |
objectId | string | Yes | HubSpot internal record ID to fetch. |
properties | string[] | No | List of property names to include in the response. Defaults to all properties. |
Returns
| Field | Type | Description |
|---|---|---|
id | string | HubSpot record ID. |
properties | object | Property values for the record. |
Throws
[xHubspot] customObjects.getById requires an objectType— ifobjectTypeis missing.[xHubspot] customObjects.getById requires an objectId— ifobjectIdis 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
- customObjects.create — create a new custom object record
- customObjects.update — update properties on a record
- customObjects.list — list all records for a type
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 }
