Loading...
Loading...
Expert guidance for building with DatoCMS headless CMS. Includes API decision guides (CDA vs CMA), executable workflow playbooks for schema management, content operations, asset uploads, migrations, structured text (DAST), webhooks, and framework integrations. Covers official MCP server integration and troubleshooting.
npx skill4agent add jodusnodus/datocms-skill datocmsimport { executeQuery } from '@datocms/cda-client';
const result = await executeQuery(query, {
token: process.env.DATOCMS_API_TOKEN,
environment: 'main'
});import { buildClient } from '@datocms/cma-client-node';
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
// Create a record
const record = await client.items.create({
item_type: { type: 'item_type', id: 'blog_post' },
title: 'New Post',
content: 'Content here'
});# For content fetching
npm install @datocms/cda-client
# For content management
npm install @datocms/cma-client-node
# For React/Next.js
npm install react-datocmsimport { executeQuery } from '@datocms/cda-client';
const query = `
query {
allBlogPosts {
id
title
slug
publishedAt
}
}
`;
const data = await executeQuery(query, {
token: process.env.DATOCMS_API_TOKEN
});import { buildClient } from '@datocms/cma-client-node';
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
// Create a model
const model = await client.itemTypes.create({
name: 'Blog Post',
api_key: 'blog_post',
singleton: false
});
// Add fields
await client.fields.create(model.id, {
label: 'Title',
field_type: 'string',
api_key: 'title',
validators: { required: {} }
});
await client.fields.create(model.id, {
label: 'Content',
field_type: 'structured_text',
api_key: 'content'
});// Create draft
const draft = await client.items.create({
item_type: { type: 'item_type', id: 'blog_post' },
title: 'My Post',
content: { /* DAST structure */ }
});
// Update
await client.items.update(draft.id, {
title: 'Updated Title'
});
// Publish
await client.items.publish(draft.id);
// Unpublish
await client.items.unpublish(draft.id);
// Delete
await client.items.destroy(draft.id);import { buildClient } from '@datocms/cma-client-node';
import fs from 'fs';
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
// Step 1: Create upload request
const path = './image.jpg';
const uploadRequest = await client.uploads.createFromFileOrBlob({
fileOrBlob: fs.createReadStream(path),
filename: 'image.jpg'
});
// Step 2: Use upload in a record
await client.items.create({
item_type: { type: 'item_type', id: 'blog_post' },
title: 'Post with Image',
cover_image: {
upload_id: uploadRequest.id
}
});# Create sandbox environment
# (Do this in DatoCMS UI: Settings > Environments)
# Make changes in sandbox
DATOCMS_ENVIRONMENT=sandbox node update-schema.js
# Test in sandbox
# Preview at: https://your-project.admin.datocms.com/editor?environment=sandbox
# Promote to primary environment (via UI or API)import { render } from 'datocms-structured-text-to-html-string';
// DAST structure
const structuredText = {
schema: 'dast',
document: {
type: 'root',
children: [
{
type: 'heading',
level: 1,
children: [{ type: 'span', value: 'Hello World' }]
},
{
type: 'paragraph',
children: [
{ type: 'span', value: 'This is ' },
{ type: 'span', marks: ['strong'], value: 'bold text' }
]
}
]
}
};
// Render to HTML
const html = render(structuredText);// Create webhook via CMA
const webhook = await client.webhooks.create({
name: 'Deploy on Publish',
url: 'https://api.vercel.com/v1/integrations/deploy/...',
events: [
{ entity_type: 'item', event_types: ['publish', 'unpublish'] }
],
http_basic_user: 'user',
http_basic_password: 'pass'
});// app/blog/page.tsx
import { executeQuery } from '@datocms/cda-client';
const query = `
query {
allBlogPosts(orderBy: publishedAt_DESC) {
id
title
slug
excerpt
}
}
`;
export default async function BlogPage() {
const { allBlogPosts } = await executeQuery(query, {
token: process.env.DATOCMS_API_TOKEN!
});
return (
<div>
{allBlogPosts.map(post => (
<article key={post.id}>
<h2>{post.title}</h2>
<p>{post.excerpt}</p>
</article>
))}
</div>
);
}{
"mcpServers": {
"datocms": {
"command": "npx",
"args": ["-y", "@datocms/mcp-server"],
"env": {
"DATOCMS_API_TOKEN": "your-full-access-token"
}
}
}
}list_modelsget_modellist_recordsget_recordcreate_recordupdate_recorddelete_recordapi_keyidcreateFromFileOrBlob