Sorry, no results found for "".

Show examples in:
Javascript HTTP

Content Management API > Record

Publish a record

When the draft/published system is enabled for a model, records will remain in a Draft status until they are Published.

When publishing a record, you can choose to either publish the whole record, or just some of its locales / non-localized content. This is similar to how the "Publish" dropdown button in the UI works.

This is the default behavior when you don't provide a request body.

This will publish the entire record, including all its localized and non-localized fields.

Do not include a request body at all — not even an empty object {}.

(No request body)

PUT https://site-api.datocms.com/items/:item_id/publish HTTP/1.1
Authorization: Bearer YOUR-API-TOKEN
Accept: application/json
X-Api-Version: 3
Content-Type: application/vnd.api+json

(No request body)

Terminal window
curl -g 'https://site-api.datocms.com/items/:item_id/publish' \
-X PUT \
-H "Authorization: Bearer YOUR-API-TOKEN" \
-H "Accept: application/json" \
-H "X-Api-Version: 3" \
-H "Content-Type: application/vnd.api+json"

(No request body)

await fetch("https://site-api.datocms.com/items/:item_id/publish", {
method: "PUT",
headers: {
Authorization: "Bearer YOUR-API-TOKEN",
Accept: "application/json",
"X-Api-Version": "3",
"Content-Type": "application/vnd.api+json",
},
});

Published item:

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
{
"id": "WxrWMPl3TjeSJYcl6lNCbg",
"type": "item",
"localized_title": {
"en": "New English title",
"es": "New Spanish title",
"it": "New Italian title"
},
"non_localized_field": "New lorem ipsum",
"item_type": {
"id": "CcW1FAf4Sd20dAZijsbzuQ",
"type": "item_type"
},
"creator": {
"id": "627975",
"type": "organization"
},
"meta": {
"created_at": "2024-01-04T23:02:07.204+00:00",
"updated_at": "2024-01-04T23:03:53.121+00:00",
"published_at": "2024-01-04T23:03:21.566+00:00",
"publication_scheduled_at": null,
"unpublishing_scheduled_at": null,
"first_published_at": "2024-01-04T23:03:21.566+00:00",
"is_valid": true,
"is_current_version_valid": true,
"is_published_version_valid": true,
"status": "updated",
"current_version": "WEU_H0i2S8mkaV7ML8OTqw",
"stage": null
}
}

Selective publishing is used when you don't want to publish the entire record. Instead, you can publish a combination of:

In this example, we will only publish the en locale. The it and es versions of localized_title will not be published, and will retain their previously published titles. non_localized_field will also keep its previously published value.

Publishing only the "en" locale

PUT https://site-api.datocms.com/items/:item_id/publish HTTP/1.1
Authorization: Bearer YOUR-API-TOKEN
Accept: application/json
X-Api-Version: 3
Content-Type: application/vnd.api+json
{
"data": {
"type": "selective_publish_operation",
"attributes": {
"content_in_locales": [
"en"
],
"non_localized_content": false
}
}
}

Publishing only the "en" locale

Terminal window
curl -g 'https://site-api.datocms.com/items/:item_id/publish' \
-X PUT \
-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":"selective_publish_operation","attributes":{"content_in_locales":["en"],"non_localized_content":false}}}'

Publishing only the "en" locale

await fetch("https://site-api.datocms.com/items/:item_id/publish", {
method: "PUT",
headers: {
Authorization: "Bearer YOUR-API-TOKEN",
Accept: "application/json",
"X-Api-Version": "3",
"Content-Type": "application/vnd.api+json",
},
body: JSON.stringify({
data: {
type: "selective_publish_operation",
attributes: { content_in_locales: ["en"], non_localized_content: false },
},
}),
});

Published item with new English title. The Italian localized field and non-localized slug remain unchanged.

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
{
"id": "WxrWMPl3TjeSJYcl6lNCbg",
"type": "item",
"localized_title": {
"en": "New English title",
"es": "Old Spanish title",
"it": "Old Italian title"
},
"non_localized_field": "Old lorem ipsum",
"item_type": {
"id": "CcW1FAf4Sd20dAZijsbzuQ",
"type": "item_type"
},
"creator": {
"id": "627975",
"type": "organization"
},
"meta": {
"created_at": "2024-01-04T23:02:07.204+00:00",
"updated_at": "2024-01-04T23:03:53.121+00:00",
"published_at": "2024-01-04T23:03:21.566+00:00",
"publication_scheduled_at": null,
"unpublishing_scheduled_at": null,
"first_published_at": "2024-01-04T23:03:21.566+00:00",
"is_valid": true,
"is_current_version_valid": true,
"is_published_version_valid": true,
"status": "updated",
"current_version": "WEU_H0i2S8mkaV7ML8OTqw",
"stage": null
}
}

Query parameters

recursive boolean

When recursive is true, if the record belongs to a tree-like collection, and any of the parent records aren't published, those parent records will published as well. When recursive is false or not specified, an UNPUBLISHED_PARENT error will occur in such cases.

Body parameters

For this endpoint, the body is not required and can be entirely omitted.
type string Required

Must be exactly "selective_publish_operation". Publish only the specified locales & non-localized content (see following attributes). To publish the entire record, simply avoid passing a request body to the endpoint.

attributes.content_in_locales Required

Array of valid locale codes in this project to publish.

Type: Array<string>
Examples: ["en"] , ["en", "it"]
attributes.non_localized_content boolean Required

Whether non-localized content will be published

Returns

Returns a resource object of type item.