For Modular Content, Structured Text and Single Block fields. If set, returns full payload for nested blocks instead of IDs
Whether you want the currently published versions (published
, default) of your records, or the latest available (current
)
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();
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 securelyconst 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 responseconsole.dir(records, { depth: null });}run();