Sorry, no results found for "".

Show examples in:
Javascript HTTP

Content Management API > Record

Retrieve a record
📚 New to DatoCMS records?

Begin by reading the Introduction to records guide to familiarize yourself with field types, API response modes, and the concepts of block manipulation!

To retrieve a single record, send a GET request to the /items/:id endpoint.

Response modes: Regular vs. Nested

The GET /items/:id endpoint, just like the List all records endpoint, supports two different response modes that control how block fields are returned in the JSON payload. You can switch between them using the nested query parameter.

  • Regular mode (default): This is the most efficient mode for listing records. Any block fields (like Modular Content) will contain an array of block IDs, not the full block content. This keeps the response size small and fast.

  • Nested mode (nested=true): This mode returns the complete content for any block fields. Instead of just IDs, the API will return full block objects, including all their attributes. This is useful when you need to display the blocks' content immediately without making additional API calls, or to read existing content and then make an update.

import { buildClient } from "@datocms/cma-client-node";
async function run() {
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
const itemId = "hWl-mnkWRYmMCSTq4z_piQ";
const item = await client.items.find(itemId);
// Check the 'Returned output' tab for the result ☝️
console.log(item);
}
run();
{
id: "hWl-mnkWRYmMCSTq4z_piQ",
title: "My first blog post!",
content: "Lorem ipsum dolor sit amet...",
category: "24",
image: {
alt: "Alt text",
title: "Image title",
custom_data: {},
focal_point: null,
upload_id: "20042921",
},
meta: {
created_at: "2020-04-21T07:57:11.124Z",
updated_at: "2020-04-21T07:57:11.124Z",
published_at: "2020-04-21T07:57:11.124Z",
first_published_at: "2020-04-21T07:57:11.124Z",
publication_scheduled_at: "2020-04-21T07:57:11.124Z",
unpublishing_scheduled_at: "2020-04-21T07:57:11.124Z",
status: "published",
is_current_version_valid: true,
is_published_version_valid: true,
current_version: "4234",
stage: null,
has_children: true,
},
item_type: { type: "item_type", id: "DxMaW10UQiCmZcuuA-IkkA" },
}

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

By default, those nested blocks are returned as block IDs (ie. "dhVR2HqgRVCTGFi_0bWqLqA"), 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();
{
id: "FEzWmQhjQgeHsCrUtvlEMw",
type: "item",
structured_text_field: {
schema: "dast",
document: {
children: [
{
item: {
type: "item",
attributes: {
button_label: "Example button",
button_url: "https://www.example.com",
},
relationships: {
item_type: {
data: { id: "SkVjHJSGR5CyK16E8TfJxg", type: "item_type" },
},
},
id: "ahxSnFQEQ02K3TjttWAg-Q",
},
type: "block",
},
{
item: {
type: "item",
attributes: {
nested_structured_text_field: {
schema: "dast",
document: {
children: [
{
children: [
{ type: "span", value: "This is a " },
{
marks: ["emphasis"],
type: "span",
value: "nested",
},
{
type: "span",
value: " structured text block inside the parent structured text field.",
},
],
type: "paragraph",
},
{
item: {
type: "item",
attributes: {
button_label: "And this is a button inside the nested structured text block",
button_url: "https://www.example2.com",
},
relationships: {
item_type: {
data: {
id: "SkVjHJSGR5CyK16E8TfJxg",
type: "item_type",
},
},
},
id: "CGqwjPDsTHKGFy1IbC0RAQ",
},
type: "block",
},
],
type: "root",
},
},
},
relationships: {
item_type: {
data: { id: "Ty4S40cbQH6_VMNnGdd9KA", type: "item_type" },
},
},
id: "AppHB06oRBm-er3oooL_LA",
},
type: "block",
},
],
type: "root",
},
},
item_type: { id: "UVa_hHEBSeefLEUnwoQFig", type: "item_type" },
creator: { id: "104280", type: "account" },
meta: {
created_at: "2024-03-13T17:01:19.243+00:00",
updated_at: "2024-03-13T17:14:17.444+00:00",
published_at: "2024-03-13T17:14:17.597+00:00",
publication_scheduled_at: null,
unpublishing_scheduled_at: null,
first_published_at: "2024-03-13T17:01:19.326+00:00",
is_valid: true,
is_current_version_valid: true,
is_published_version_valid: true,
status: "published",
current_version: "DLtyHZ2MTDqYMg7g5mgYEw",
stage: null,
},
}

Query parameters

nested boolean

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

version string

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

Example: "published"

Returns

Returns a resource object of type item