Previewing drafts via the API

When we prepare a new record - in our case, a blog article - in DatoCMS we would like to be able to see how our frontend, which fetches the data via the DatoCMS API, will render the content before publish it live to our website. So we would like see draft articles when running our site on a development machine or in a pre-production environment.

What is the best practice for achieving this? I read the article on the draft/published system, but it states that records in draft state will not be returned from the API.

Should I create my own custom field - say “Production” - and filter based on that in the production site but not in the pre-production ones?

Thanks in advance.

1 Like

hello @alexis! :slight_smile:

You are right, the documentation is not clear about that, I’ll try to improve that.

Meanwhile, the data in draft is available via the API, just at another endpoint for GraphQL:

And in the REST API you need to specify if you want the “draft” or the “published” version for example here: