How can I get blocks of structured text field using CMA

How can I get blocks of a structured text field along with the value using content management API?

You can use the nested attribute to fetch records with their block records ( List all records - Record - Content Management API ).

You can use nested even with a single record fetch, but our documentation is outdated (thanks for this! Iโ€™ll update it)

For example:

const { SiteClient } = require("datocms-client");
const client = new SiteClient("<TOKEN>");

async function getRecord() {
  const record = await client.items.find("<RECORD-ID>", {
    nested: true,
  });
  console.log(JSON.stringify(record));
}

getRecord();

2 Likes

Thanks for your answer. Can we have something like graphql api - blocks and value are 2 separate fields which can be rendered by react-datocms library?

also links along with blocks as is in graphql api

unfortunately not, the React component is made to work with the GraphQL API, which is the preferred way to read content.

same here, whatโ€™s your use case? Why canโ€™t you use the GraphQL API directly?

we wanted to cache/manipulate data on webhook calls.

sorry, I donโ€™t understand what you are trying to do here. Are you trying to write back to us something? If so why are you concerned with the React component?

Sorry about the misunderstanding. Please ignore this.