Was this page helpful?

Determine the state of entries and assets

Overview

Content entities (entries and assets) can have different states. This article explains what these states are, how to access them and how to determine state by evaluating the sys property of paylods.

The four states are:

  • Draft: A draft entity is not published. Only the Content Management API and Content Preview API can access entities in draft state.
  • Changed: An updated entity is published but has pending changes. Pending changes are only accessible from the Content Management API and Content Preview API. If the entity is fetched from the Content Delivery API it will be in its last published state.
  • Published: A published entity is published and has no been modified since. No matter which API is used to fetch it, the same content will be retrieved.
  • Archived: An archived entity is not published and can not be edited. Archived entities can be retrived using the Content Management API when quering for sys.archivedAt[exists]=true

The picture above shows the different state of entries in the Contentful Web App.

Detecting state

The sys property of entities holds properties which can be used to detect its state.

Detect if an entity is in draft state:

function isDraft(entity) {
  return !!entity.sys.publishedVersion
}

Detect if an entity is in changed state:

function isChanged(entity) {
  return !!entity.sys.publishedVersion &&
    entity.sys.version >= entity.sys.publishedVersion + 2)
}

Detect if an entity is in published state:

function isPublished(entity) {
  return !!entity.sys.publishedVersion &&
    entity.sys.version == entity.sys.publishedVersion + 1)
}

Detect if an entity is in archived state:

function isArchived(entity) {
  return !!entity.sys.archivedVersion
}

Conclusion

Understanding the values of certain properties of entity.sys allows to detect the state of an entity. The same applies to the UI Extensions SDK when working with entires: The sys property of entries is available as well.