Show examples in:
Javascript HTTP
Content Management API > Record

Create a new record

📚 New to DatoCMS records?

Before creating your first record, we strongly recommend reading the Introduction to Records guide. It covers fundamental concepts about field types, block manipulation, and localization that are essential for building a valid creation payload.

The payload required to create a new record is determined by the specific model it's based on and the fields it contains.

When creating a record, you don't need to specify a value for every field. Any field you omit will be set to its configured default value, or null if no default is set.

While the Introduction to Records guide offers a complete reference for every field type, there are several key rules that are especially important when creating a new record.

TypeScript typing

Writing a create payload without typed schemas means writing blind: every field is unknown, typos compile fine, and mistakes only surface as 422s from the API. The single biggest lever you have is passing a generated Schema.X marker as the generic on items.create. TypeScript then enforces the model's field names, types, and allowed block shapes at compile time:

// ❌ Untyped: every field is `unknown`, typos compile.
await client.items.create({ /* … */ });
// ✅ Typed: field names, types, and block shapes enforced.
await client.items.create<Schema.Article>({ /* … */ });

When you need the actual TypeScript type of a single field — to annotate a helper, an intermediate variable, or a function parameter — reach for FieldValueInRequest<T, 'field_key'>. The first argument is the Schema.X marker for the model that owns the field:

⚠️ A marker can't be indexed directly

Schema.Article is a phantom type marker, not a record shape. Writing Schema.Article["content"] won't give you the field type.

// ❌ Markers aren't indexable
type Content = Schema.Article["content"];
// ✅ Use the helper instead
type Content = NonNullable<FieldValueInRequest<Schema.Article, "content">>;
function buildSections(
page: ApiTypes.ItemInNestedResponse,
): NonNullable<FieldValueInRequest<Schema.LandingPage, "sections">> {
// …assemble and return the sections array…
}
await client.items.create<Schema.LandingPage>({
item_type: Schema.LandingPage.REF,
title: "Product Launch Landing Page",
sections: buildSections(sourcePage),
});

The first argument also accepts an item-shaped value the CMA already produced — useful when you're cloning or migrating from an existing record:

const source = await client.items.find<Schema.Article>("source-id", { nested: true });
if (source.content) {
const content: NonNullable<FieldValueInRequest<typeof source, "content">> =
/* …transform source.content… */;
await client.items.create<Schema.Article>({ item_type: Schema.Article.REF, content });
}
⚠️ Field values are always nullable

Even fields with a required validator are typed as Nullable, because the API may still accept/return null in some scenarios. Wrap the helper in NonNullable<…> when you need the non-null shape.

📖 Read-side counterparts

FieldValueInRequest is the write-side helper. For values coming back from the API, use FieldValue<T, 'field_key'> (regular responses) or FieldValueInNestedResponse<T, 'field_key'> (when you fetched with nested: true). All three follow the same <marker-or-value, fieldKey> shape — see the Item resource overview for the full helper family.

Field value formatting

Every field in your payload must be formatted according to its type. This can range from a simple string or number to a structured object. For a comprehensive breakdown of the expected format for every field type, please refer to the Field Types Overview in our main records guide.

Block Fields

When creating a record, any new blocks (for Modular Content, Single Block, or Structured Text fields) must be provided as full block objects. This object must include the item_type in its relationships to specify which Block Model to use. For a deeper dive into manipulating blocks, see the guide on Creating and Updating Blocks.

Asset & Link Fields

These reference fields require specific formats. For a comprehensive breakdown of the expected format for every field type, please refer to the Field Types Overview in our main records guide.

Localization

If the record's model contains localized fields, your creation payload must adhere to specific rules:

  • All localized fields in a single payload must specify the same set of locales to ensure consistency.
  • If the model is configured to require all locales (all_locales_required), then the payload must include a key for every available locale for each localized field. The value of a field for a locale can be null, but the key itself is mandatory.

For a full explanation of how to structure localized data, refer to the localization Guide.

Body parameters

id string Optional

RFC 4122 UUID of record expressed in URL-safe base64 format

Example: "hWl-mnkWRYmMCSTq4z_piQ"
type string Required

Must be exactly "item".

meta.created_at string Optional

Date of creation

meta.first_published_at null, string Optional

Date of first publication

relationships.item_type.data Required

The record's model

relationships.creator.data Optional

The entity (account/collaborator/access token/sso user) who created the record

Returns

Returns a resource object of type item.

Examples

POST https://site-api.datocms.com/items HTTP/1.1
Authorization: Bearer YOUR-API-TOKEN
Accept: application/json
X-Api-Version: 3
Content-Type: application/vnd.api+json
{
"data": {
"type": "item",
"attributes": {
"title": "My first blog post!",
"content": "Lorem ipsum dolor sit amet...",
"category": "24",
"image": {
"upload_id": "WxrWMPl3TjeSJYcl6lNCbg",
"alt": "Alt text",
"title": "Image title",
"custom_data": {}
}
},
"relationships": {
"item_type": {
"data": {
"type": "item_type",
"id": "DxMaW10UQiCmZcuuA-IkkA"
}
}
}
}
}
Terminal window
curl -g 'https://site-api.datocms.com/items' \
-X POST \
-H "Authorization: Bearer YOUR-API-TOKEN" \
-H "Accept: application/json" \
-H "X-Api-Version: 3" \
-H "Content-Type: application/vnd.api+json" \
--data-binary '{"data":{"type":"item","attributes":{"title":"My first blog post!","content":"Lorem ipsum dolor sit amet...","category":"24","image":{"upload_id":"WxrWMPl3TjeSJYcl6lNCbg","alt":"Alt text","title":"Image title","custom_data":{}}},"relationships":{"item_type":{"data":{"type":"item_type","id":"DxMaW10UQiCmZcuuA-IkkA"}}}}}'
await fetch("https://site-api.datocms.com/items", {
method: "POST",
headers: {
Authorization: "Bearer YOUR-API-TOKEN",
Accept: "application/json",
"X-Api-Version": "3",
"Content-Type": "application/vnd.api+json",
},
body: JSON.stringify({
data: {
type: "item",
attributes: {
title: "My first blog post!",
content: "Lorem ipsum dolor sit amet...",
category: "24",
image: {
upload_id: "WxrWMPl3TjeSJYcl6lNCbg",
alt: "Alt text",
title: "Image title",
custom_data: {},
},
},
relationships: {
item_type: {
data: { type: "item_type", id: "DxMaW10UQiCmZcuuA-IkkA" },
},
},
},
}),
});
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: cache-control: max-age=0, private, must-revalidate
X-RateLimit-Limit: 30
X-RateLimit-Remaining: 28
{
"data": {
"type": "item",
"id": "hWl-mnkWRYmMCSTq4z_piQ",
"relationships": {
"item_type": {
"data": {
"type": "item_type",
"id": "DxMaW10UQiCmZcuuA-IkkA"
}
}
},
"attributes": {
"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
}
},
"included": [
{
"type": "item_type",
"id": "DxMaW10UQiCmZcuuA-IkkA",
"relationships": {
"singleton_item": {
"data": null
},
"fields": {
"data": [
{
"type": "field",
"id": "Pkg-oztERp6o-Rj76nYKJg"
}
]
},
"fieldsets": {
"data": [
{
"type": "fieldset",
"id": "93Y1C2sySkG4Eg0atBRIwg"
}
]
},
"presentation_title_field": {
"data": null
},
"presentation_image_field": {
"data": null
},
"title_field": {
"data": null
},
"image_preview_field": {
"data": null
},
"excerpt_field": {
"data": null
},
"ordering_field": {
"data": null
},
"workflow": {
"data": null
}
},
"attributes": {
"name": "Blog post",
"api_key": "post",
"singleton": false,
"sortable": true,
"modular_block": false,
"tree": false,
"ordering_direction": null,
"ordering_meta": "created_at",
"draft_mode_active": false,
"all_locales_required": false,
"collection_appearance": "compact",
"hint": "Blog posts will be shown in our website under the Blog section",
"inverse_relationships_enabled": false,
"draft_saving_active": false
},
"meta": {
"has_singleton_item": false
}
}
]
}