Content Management API > Record
Create a new record
Body parameters
id string Optional
RFC 4122 UUID of record expressed in URL-safe base64 format
Example:
"hWl-mnkWRYmMCSTq4z_piQ"
meta.created_at string Optional
Date of creation
meta.first_published_at null, string Optional
Date of first publication
creator Optional
The entity (account/collaborator/access token/sso user) who created the record
Returns
Returns a resource object of type item
Other examples
This example demonstrates how to create records in tree-structured collections, where records can form hierarchical relationships with parent-child connections. Tree structures are useful for navigation menus, category hierarchies, organizational charts, and any content that needs nested organization.
When creating records in tree-like collections, you can specify:
parent_id: Links the record to its parent in the hierarchyposition: Sets the ordering among sibling records
The example shows how to build a hierarchy by creating records that reference each other:
import { buildClient, type ItemTypeDefinition, inspectItem,} from "@datocms/cma-client-node";
type EnvironmentSettings = { locales: "en" };
// 👇 Definitions can be generated automatically using CLI: https://www.datocms.com/cma-ts-schema
type Category = ItemTypeDefinition< EnvironmentSettings, "UZyfjdBES8y2W2ruMEHSoA", { name: { type: "string" }; parent_id: { type: "string" }; position: { type: "integer" }; }>;
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 parent = await client.items.create<Category>({ item_type: { type: "item_type", id: "UZyfjdBES8y2W2ruMEHSoA" }, name: "Parent", });
console.log(inspectItem(parent));
const child1 = await client.items.create<Category>({ item_type: { type: "item_type", id: "UZyfjdBES8y2W2ruMEHSoA" }, name: "Child 1", parent_id: parent.id, position: 1, });
console.log(inspectItem(child1));
const child2 = await client.items.create<Category>({ item_type: { type: "item_type", id: "UZyfjdBES8y2W2ruMEHSoA" }, name: "Child 2", parent_id: parent.id, position: 2, });
console.log(inspectItem(child2));}
run();└ Item "Ov5N1h4_QwW89_IzbUBb4g" (item_type: "UZyfjdBES8y2W2ruMEHSoA") ├ name: "Parent" ├ position: 1 └ parent_id: null
└ Item "a8A-nl0cRXCqBNniQMAxog" (item_type: "UZyfjdBES8y2W2ruMEHSoA") ├ name: "Child 1" ├ position: 1 └ parent_id: "Ov5N1h4_QwW89_IzbUBb4g"
└ Item "d6Gl9tPMSTqSF2bOMIcOYw" (item_type: "UZyfjdBES8y2W2ruMEHSoA") ├ name: "Child 2" ├ position: 2 └ parent_id: "Ov5N1h4_QwW89_IzbUBb4g"