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.
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.
Array of valid locale codes in this project to publish.
Whether non-localized content will be published
If you're using the the older, now-deprecated datocms-client
instead of the current @datocms/cma-client
, there is a known issue with the item.publish()
method. It will return an error like:
{"data": [{"id": "abcdef","type": "api_error","attributes": {"code": "INVALID_FORMAT","details": {"messages": ["#/data: failed schema #/definitions/item/links/13/schema/properties/data: \"id\" is not a permitted key."]}}}]}
The workaround is to add {serializeRequest: false}
as the third parameter of that method, like:
await client.item.publish("1234567890", // record ID{}, // body{}, // query string{ serializeRequest: false } // this is the actual workaround);
This tells the deprecated client to skip some of its internal serialization rules (which used to work, but no longer) and instead just send the raw syntax that you provide.
While this should allow that method to continue working for the time being, it is important that you upgrade to the modern client as soon as possible. As of 2024, the old client has been deprecated for more than 2 years and will not receive any further updates. It is possible that this method and others will further break over time, possibly impacting production workflows.
import { buildClient } from "@datocms/cma-client-node";async function run() {const client = buildClient({ apiToken: "API_TOKEN" });const itemId = "WxrWMPl3TjeSJYcl6lNCbg";const publishedRecord = await client.items.publish(itemId,{}, // body{}, // query string{ serializeRequest: false }, // this is the actual workaround);console.log(publishedRecord);}run();