Get only validated content

Hi, it seems whenever you query for content I also receive content in an “invalid state”, which makes me modify my code to add too many ifs to know if a property exists (even though its required on contentful) and also my app will constantly fail cause I keep on fetching content which does not meet the required validations of the object after a content model gets modified.
Is it possible to only fetch content which is on a valid state?

So, one month and a half later there is no answer to such a simple question?

Hey Gabriel,

Sorry you haven’t received a response yet. This is a community forum and while we do monitor it, we don’t always get to every question.

To answer your question, when using the Content Management API or Content Preview API you will get all content as it’s currently in your space, including drafts and drafts that don’t validate. The reason that happens is that we only check validations in our API when publishing. The only way to guarantee you only receive valid entries is to use the Content Delivery API.

Hi @Rouven, thx for getting back. Well I thought as soon as I’m using this Javascript SDK with a non Preview token I should be accessing the Contentful Delivery API as the documentation says, but I does not seem to be the case cause I still receive invalid content. Unless you tell documentation of the SDK is incorrect or I’m doing something wrong.

If you use that SDK (contentful.js), with a delivery token and don’t override the host parameter that you will receive only published content.

Did you perhaps add a validation after publishing the entry? In that case you will still receive invalid content since we only check validation while publishing.

Is there any way to un-publish contents automatically when a validation is added after publishing the entries?