Show examples in:
Retrieve a record

Query parameters

nested  Optional  boolean  Example: true

For Modular Content, Structured Text and Single Block fields. If set, returns full payload for nested blocks instead of IDs

version  Optional  string  Example: "published"

Whether you want the currently published versions (published, default) of your records, or the latest available (current)

Returns

Returns a item resource object.

Examples

Example Basic example
import { buildClient } from '@datocms/cma-client-node';
async function run() {
const client = buildClient({ apiToken: '<YOUR_API_TOKEN>' });
const itemId = 'hWl-mnkWRYmMCSTq4z_piQ';
const item = await client.items.find(itemId);
console.log(item);
}
run();
Example Fetching nested blocks inside the record

Sometimes, you may wish to fetch a record that has embedded blocks inside Structured Text or Modular Content fields.

By default, those nested blocks are returned as references, like:

[
{ item: 'ahxSnFQEQ02K3TjttWAg-Q', type: 'block' },
{ item: 'AppHB06oRBm-er3oooL_LA', type: 'block' }
]

But if you add the nested: true query parameter, we'll embed the blocks content inline for you.

import { buildClient } from "@datocms/cma-client-node";
async function run() {
// Make sure the API token has access to the CMA, and is stored securely
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
const records = await client.items.find("FEzWmQhjQgeHsCrUtvlEMw", {
nested: true, // Retrieve its nested block content as well
});
// Instead of console.log, console.dir will fully expand nested objects
// See https://nodejs.org/api/console.html#consoledirobj-options
// This way, we can better see the embedded blocks in the response
console.dir(records, { depth: null });
}
run();