Contentful logo

Contentful Community

Correct way to fetch entries with draft status

I’m trying to use the Python CMA SDK to fetch entries filtered by a query (though I assume this works the same at API level). Ideally, one aspect of the query is to only return ‘draft’ entries. I’ve tried using an exists condition on publication datetime–

env.entries().all(
        {
            'content_type': 'my_content_type',
            'sys.publishedAt[exists]': False
        }
)

–but this doesn’t seem to work. Is this not the correct name for the field? Or maybe this type of query is just not possible?

Thanks.

Hi @mark2,

In this case, If you use the Content Management API, the sys.publishedVersion property indicates the version of the document that was published.

if sys.version = sys.publishedVersion + 1 then it means the document in the management API is exactly in the state as it was published.

if sys.version > sys.publishedVersion + 1 the it means that the document was published but there have been changes since the last time it was published.

In order to query from the api all entries that have a change you can use the changed=true parameter in the Content Management API calls. With that, you should be able to track those items that have published and those that have not

2 Likes