The payload to pass to create a new record always depends on the specific settings of its model and the fields it declares.
When creating a new record, you don't need to specify a value for every field of it's model, as the ones you don't specify will be set to the field's default value (if available), or null
(which is a valid value for every type of field).
If you do want to provide an explicit value for a field, then each type of field requires a different type of value. Most of the field types require scalar values — ie. a Single-line string requires a string, an Integer field requires a number, etc:
Some other fields, like Geo-location or Color fields, require objects instead of simple data types:
1{2 // If the model has a `location` field of type 'Geo-location'...3 "location": { "latitude": 45.0703393, "longitude": 7.686864 },4 // If the model has an `accent_color` field of type 'Color'...5 "accent_color": { "red": 239, "green": 208, "blue": 156, "alpha": 255 }6}
We'll analyze in detail every different type of field that DatoCMS offers in the following examples.
Fields can be localized. If that's the case, records need to express a value for multiple locales using an object, whose keys represent the locale itself.
If your model has the "All locales required?" option turned on, then you MUST express a field value for all environment's locales:
1{2 // If the model has a `title` single-line string field...3 "name": {4 "en": "Alfie",5 "it": "Asso"6 },7 // If the model has an `color` field...8 "age": {9 "en": { "red": 255, "green": 0, "blue": 0, "alpha": 255 },10 "it": { "red": 0, "green": 255, "blue": 0, "alpha": 255 }11 }12 // And so on :)13}
Otherwise, you can just define a subset of them (as long as all localized fields express the exact same subset!):
1{2 // Even if the environment has many locales, since the model has the "All locales required?" option3 // turned off, we can define only the Italian locale:4 "name": {5 "it": "Asso"6 },7 "age": {8 "it": { "red": 0, "green": 255, "blue": 0, "alpha": 255 }9 }10}
The field accepts String
values.
The field accepts simple String
values.
The field accepts simple Boolean
values.
The field accepts simple Integer
values.
The field accepts simple Float
values.
The field accepts String
values in ISO 8601 date format (ie. "2015-12-29"
).
The field accepts String
values in ISO 8601 date-time format (ie. "2020-04-17T16:34:31.981+01:00"
).
If you're on legacy timezone management, remember that when sending an ISO8601 datetime you should keep in mind that the system will ignore any provided timezone, and will use the project's timezone instead.
The field accepts an object with the following properties:
Property | Required | Type |
---|---|---|
red | ✅ | Integer between 0 and 255 |
green | ✅ | Integer between 0 and 255 |
blue | ✅ | Integer between 0 and 255 |
alpha | ✅ | Integer between 0 and 255 |
The field accepts String
values that are valid JSON.
The field accepts an object with the following properties:
Property | Required | Type |
---|---|---|
latitude | ✅ | Float between -90.0 to 90 |
longitude | ✅ | Float between -180.0 to 180 |
The field accepts an object with the following properties:
Property | Required | Type | Description |
---|---|---|---|
title | String | Title meta tag (max. 320 characters) | |
description | String | Description meta tag (max. 320 characters) | |
image | Upload ID | Asset to be used for social shares | |
twitter_card | "summary" , "summary_large_image" | Type of Twitter card to use | |
no_index | Boolean | Whether the noindex meta tag should be returned |
The field accepts String
values that satisfy the following regular expression: /^[a-z0-9_]+(?:\-[a-z0-9]+)*$/
.
The field accepts an object with the following properties:
Property | Required | Type | Description | Example |
---|---|---|---|---|
provider | ✅ | "youtube" , "vimeo" , "facebook" | External video provider | "youtube" |
provider_uid | ✅ | String | Unique identifier of the video within the provider | "vUdGBEb1i9g" |
url | ✅ | URL | URL of the video | "https://www.youtube.com/watch?v=qJhobECFQYk" |
width | ✅ | Integer | Video width | 459 |
height | ✅ | Integer | Video height | 344 |
thumbnail_url | ✅ | URL | URL for the video thumb | "https://i.ytimg.com/vi/vUdGBEb1i9g/hqdefault.jpg" |
title | ✅ | String | Title of the video | "Next.js Conf Booth Welcoming!" |
The field accepts an object with the following properties:
Property | Required | Type | Description | Example |
---|---|---|---|---|
upload_id | ✅ | Upload ID | ID of an asset | "3429022" |
title | String | Title for the asset, if you want to override the asset's default value (see Upload default_field_metadata ) | "From my trip to Italy" | |
alt | String | Alternate text for the asset, if you want to override the asset's default value (see Upload default_field_metadata ) | "Florence skyline" | |
focal_point | { x: Float, y: Float } , null | Focal point for the asset, if you want to override the asset's default value (see Upload default_field_metadata ). Values must be expressed as Float between 0 and 1. Focal point can only be specified for image assets. | { "x": 0.34, "y": 0.45 } | |
custom_data | Record<String, String> | An object containing custom keys that you can use on your frontend projects | { "watermark_image": "true" } |
This field accepts an Array
of objects with the following properties:
Property | Required | Type | Description | Example |
---|---|---|---|---|
upload_id | ✅ | Upload ID | ID of an asset | "3429022" |
title | String | Title for the asset, if you want to override the asset's default value (see Upload default_field_metadata ) | "https://www.youtube.com/watch?v=vUdGBEb1i9g" | |
alt | String | Alternate text for the asset, if you want to override the asset's default value (see Upload default_field_metadata ) | "vUdGBEb1i9g" | |
focal_point | { x: Float, y: Float } , null | Focal point for the asset, if you want to override the asset's default value (see Upload default_field_metadata ). Values must be expressed as Float between 0 and 1. Focal point can only be specified for image assets. | { "x": 0.34, "y": 0.45 } | |
custom_data | Record<String, String> | An object containing custom keys that you can use on your frontend projects | { "watermark_image": "true" } |
This field accepts a String
representing the ID of the linked record.
This field accepts an Array<String>
representing the IDs of the linked records.
When a record is being read, this field returns an Array<String>
representing the IDs of the inner block records.
When a record is being created, this field must contain an Array
of objects representing the inner block records:
Example:
1[2 {3 "type": "item",4 "attributes": {5 // ... put your fields values here6 },7 "relationships": {8 "item_type": {9 "data": {10 // the block model11 "id": "435822",12 "type": "item_type",13 }14 }15 },16 },17 // ...18]
When a record is being updated, make sure to include the ID of the already existing block records, or if the block is not subject to any change, just pass its ID:
1[2 // we don't need to change anything to these two blocks, just pass their IDs:3 "9862635",4 "9862636",5 // we want to change some field values for this block!6 {7 "id": "9862637",8 "type": "item",9 "attributes": {10 // ... put the block fields to be changed here11 },12 "relationships": {13 "item_type": {14 "data": {15 // the block model16 "id": "435822",17 "type": "item_type",18 }19 }20 },21 },22]
When a record is being read, this field returns a <String>
representing the ID of the inner block record.
When a record is being created, this field must contain an object representing the inner block record:
Example:
1{2 "type": "item",3 "attributes": {4 // ... put your fields values here5 },6 "relationships": {7 "item_type": {8 "data": {9 // the block model10 "id": "435822",11 "type": "item_type",12 }13 }14 },15},16// ...
When a record is being updated, make sure to include the ID of the already existing block record, or if the block is not subject to any change, just pass its ID:
1// we don't need to change anything to this block, just pass its ID:2"9862635"
1// we want to change some field values for this block!2{3 "id": "9862637",4 "type": "item",5 "attributes": {6 // ... put the block fields to be changed here7 },8 "relationships": {9 "item_type": {10 "data": {11 // the block model12 "id": "435822",13 "type": "item_type",14 }15 }16 },17}
This field accepts a Structured Text document.
When a record is being created, the item
attribute of block
nodes must be the entire block record instead of the ID:
Example:
1{2 "schema": "dast",3 "document": {4 "type": "root",5 "children": [6 {7 "type": "block",8 "item": {9 "type": "item",10 "attributes": {11 // ... put your fields values here12 },13 "relationships": {14 "item_type": {15 "data": {16 // the block model17 "id": "435822",18 "type": "item_type",19 }20 }21 },22 }23 }24 ]25 },26}
When a record is being updated, make sure to include the ID of the already existing block records, or if the block is not subject to any change, just pass its ID:
1{2 "schema": "dast",3 "document": {4 "type": "root",5 "children": [6 {7 "type": "block",8 // this block is not subject to any change, just pass its ID9 "item": "34823428"10 },11 {12 "type": "block",13 // we want to change some field values for this block!14 "item": {15 "id": "34823424",16 "type": "item",17 "attributes": {18 // ... put the block fields to be changed here19 },20 "relationships": {21 "item_type": {22 "data": {23 // the block model24 "id": "435822",25 "type": "item_type",26 }27 }28 }29 }30 }31 ]32 }33}
RFC 4122 UUID of record expressed in URL-safe base64 format
"hWl-mnkWRYmMCSTq4z_piQ"
Must be exactly "item"
.
Date of creation
Date of first publication
The entity (account/collaborator/access token/sso user) who created the record
Returns a resource object of type item.
1POST https://site-api.datocms.com/items HTTP/1.12Authorization: Bearer YOUR-API-TOKEN3Accept: application/json4X-Api-Version: 35Content-Type: application/vnd.api+json6
7{8 "data": {9 "type": "item",10 "attributes": {11 "title": "My first blog post!",12 "content": "Lorem ipsum dolor sit amet...",13 "category": "24",14 "image": {15 "upload_id": "1235",16 "alt": "Alt text",17 "title": "Image title",18 "custom_data": {}19 }20 },21 "relationships": {22 "item_type": {23 "data": {24 "type": "item_type",25 "id": "DxMaW10UQiCmZcuuA-IkkA"26 }27 }28 }29 }30}
1curl -g 'https://site-api.datocms.com/items' \2 -X POST \3 -H "Authorization: Bearer YOUR-API-TOKEN" \4 -H "Accept: application/json" \5 -H "X-Api-Version: 3" \6 -H "Content-Type: application/vnd.api+json" \7 --data-binary '{"data":{"type":"item","attributes":{"title":"My first blog post!","content":"Lorem ipsum dolor sit amet...","category":"24","image":{"upload_id":"1235","alt":"Alt text","title":"Image title","custom_data":{}}},"relationships":{"item_type":{"data":{"type":"item_type","id":"DxMaW10UQiCmZcuuA-IkkA"}}}}}'
1await fetch("https://site-api.datocms.com/items", {2 method: "POST",3 headers: {4 Authorization: "Bearer YOUR-API-TOKEN",5 Accept: "application/json",6 "X-Api-Version": "3",7 "Content-Type": "application/vnd.api+json",8 },9 body: JSON.stringify({10 data: {11 type: "item",12 attributes: {13 title: "My first blog post!",14 content: "Lorem ipsum dolor sit amet...",15 category: "24",16 image: {17 upload_id: "1235",18 alt: "Alt text",19 title: "Image title",20 custom_data: {},21 },22 },23 relationships: {24 item_type: {25 data: { type: "item_type", id: "DxMaW10UQiCmZcuuA-IkkA" },26 },27 },28 },29 }),30});
1HTTP/1.1 200 OK2Content-Type: application/json3Cache-Control: cache-control: max-age=0, private, must-revalidate4X-RateLimit-Limit: 305X-RateLimit-Remaining: 286
7{8 "data": {9 "type": "item",10 "id": "hWl-mnkWRYmMCSTq4z_piQ",11 "relationships": {12 "item_type": {13 "data": {14 "type": "item_type",15 "id": "DxMaW10UQiCmZcuuA-IkkA"16 }17 }18 },19 "attributes": {20 "title": "My first blog post!",21 "content": "Lorem ipsum dolor sit amet...",22 "category": "24",23 "image": {24 "alt": "Alt text",25 "title": "Image title",26 "custom_data": {},27 "focal_point": null,28 "upload_id": "20042921"29 }30 },31 "meta": {32 "created_at": "2020-04-21T07:57:11.124Z",33 "updated_at": "2020-04-21T07:57:11.124Z",34 "published_at": "2020-04-21T07:57:11.124Z",35 "first_published_at": "2020-04-21T07:57:11.124Z",36 "publication_scheduled_at": "2020-04-21T07:57:11.124Z",37 "unpublishing_scheduled_at": "2020-04-21T07:57:11.124Z",38 "status": "published",39 "is_current_version_valid": true,40 "is_published_version_valid": true,41 "current_version": "4234",42 "stage": null43 }44 },45 "included": [46 {47 "type": "item_type",48 "id": "DxMaW10UQiCmZcuuA-IkkA",49 "relationships": {50 "singleton_item": {51 "data": null52 },53 "fields": {54 "data": [55 {56 "type": "field",57 "id": "Pkg-oztERp6o-Rj76nYKJg"58 }59 ]60 },61 "fieldsets": {62 "data": [63 {64 "type": "fieldset",65 "id": "93Y1C2sySkG4Eg0atBRIwg"66 }67 ]68 },69 "title_field": {70 "data": null71 },72 "image_preview_field": {73 "data": null74 },75 "excerpt_field": {76 "data": null77 },78 "ordering_field": {79 "data": null80 },81 "workflow": {82 "data": null83 }84 },85 "attributes": {86 "name": "Blog post",87 "api_key": "post",88 "singleton": false,89 "sortable": true,90 "modular_block": false,91 "tree": false,92 "ordering_direction": null,93 "ordering_meta": "created_at",94 "draft_mode_active": false,95 "all_locales_required": false,96 "collection_appearance": "compact",97 "hint": "Blog posts will be shown in our website under the Blog section",98 "inverse_relationships_enabled": false99 },100 "meta": {101 "has_singleton_item": false102 }103 }104 ]105}