The DatoCMS Blog

Introducing Draft/Published records!

Posted on March 18th, 2018 by Stefano Verna

We're extremely excited to announce the release of a much-needed feature: the ability to edit and save records and only publish them when you feel that are ready. That is, when you create a new record, or update one of your existing ones, those changes are no longer immediately reflected in the API; you can keep editing your content as long as you want, and make it public and visible to everyone when it's complete.

You can enable this feature selectively on the models that require it:

This change impacts both our administrative area interface and API, but we managed not to break old clients, so hopefully, you won't need to make any change to your existing websites.

In this article, we'll walk through every change we introduced.

Draft/Published/Updated status

First of all, on models where it's enabled, records are marked by colored dots and a status:

  • A Draft record is a record that has not been published yet. You can keep on making changes, and when you're ready you can click on the Publish button to make it public;

  • A Published record is a record that is publicly visible, and has no pending changes of any kind. You are free to unpublish it whenever you want;

  • An Updated record is a record that is currently published, but in the meantime has been modified, and those changes changes are still not published;

Just to make things more visual, this might be the lifecycle of one of your records:

API Changes

When retrieving one of your records from the API, you can decide to get the currently published version (that's probably the case for production environments), or the latest available (on staging environments, or your local development machine).

To do that, we added a version parameter to our /items and /item API endpoints. The default value, if not specified, will be published, but if you need to preview pending changes, you can set it to latest:

Terminal window
$ curl -v 'https://site-api.datocms.com/items?version=latest' \
-H 'Authorization: Bearer <API-TOKEN>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'

Changes to our clients

Both our Javascript and Ruby CLI clients have been upgraded as well to reflect this change:

Node/JS client

import { SiteClient } from 'datocms-client';
const client = new SiteClient("YOUR-API-KEY");
const records = await client.items.all({ "version": "latest" });

Ruby client

require "dato"
client = Dato::Site::Client.new("YOUR-API-KEY")
records = client.items.all(version: :latest)

"Dump" command

And our dato dump command now features a --preview flag you can activate to see the pending changes:

Terminal window
$ dato dump --preview

Middleman plugin

Our Middleman plugin now offers a preview flag as well:

config.rb
activate :dato, preview: true

Gatsby plugin

Our Gatsby source plugin offers a previewMode flag, for the same purpose of course:

1
// In your gatsby-config.js
2
plugins: [
3
{
4
resolve: `gatsby-source-datocms`,
5
options: {
6
apiToken: `YOUR_READONLY_API_TOKEN`,
7
previewMode: true
8
},
9
},
10
// ...
11
]

What's next

This is just the first step towards a more complete editorial workflow we want to make available to our users.

We're eager to collect feedback from you guys, and work together to shape the future of DatoCMS.

Start using DatoCMS today
According to Gartner 89% of companies plan to compete primarily on the basis of customer experience this year. Don't get caught unprepared.
  • No credit card
  • Easy setup
Subscribe to our newsletter! 📥
One update per month. All the latest news and sneak peeks directly in your inbox.
support@datocms.com ©2024 Dato srl, all rights reserved P.IVA 06969620480