How can I preview a scheduled content update?

I’m new to contentful, and I’m wondering how I might go about scheduling an update to an existing content item to happen on a given date, then use an api call to see this upcoming update.

I know how to add start and end datetimes to my ContentType and alter my query to include a timeOfPreview to view those items scheduled for the given time, but how might I go about viewing a future update? The only way I know to even schedule an update is to use the webhooks feature to execute the update at a given time, but now there’s no way for me to “view the exact state of a content item at a future date.” I’m at a loss on how to even begin.

Thanks,
Tim

What I’m trying to accomplish is similar to what prismic.io provides in the ability to see all past and future states of a content item. They use “refs” which stripe all their content, with each ref representing a scheduled publish.

The start and end dates that Contentful recommends adding to content for this purpose will only work with new items. They don’t address updates to existing items that are already published in some form.

If your front end queries Contentful for entries using logic like startDate < now < endDate, then it would be very easy to use a different the time (other than now) to query Contentful.

What do you mean when you say:

They don’t address updates to existing items that are already published in some form

Contentful doesn’t force you to use our idea of a scheduled publish, so there are many possible ways to do this. If you can explain more about how you’ve done it, we might could give you a better answer.

Thanks for the response.

The startDate mechanism works great for new items, or items that need to be removed from a list using the endDate. It does not work for updates, however. Let’s say I have a list of ten Products, all currently live, with a startDate in the past, and endDates in the future. Say I want to schedule an update to one of these already published products. Say I want the price to change from $90 to $100, but I want that change to take place next Tuesday at midnight. I can’t use the startDate and endDate for this, because those fields are already being used to tell the system, “this item is published between these dates”. How do I say, “update this item, with these changes, ON this date”. And how do I do it in such a way that I can preview all upcoming and past updates to the item?

You are correct in that Contentful doesn’t have the idea of scheduled publishing (including scheduling updates) built into the platform so the platform doesn’t have the concept of “the exact state of a content item at a future date”. Such a system can be modeled and built in Contentful but its not built in, out of the box.

One possible way to accomplish what you want to do involves multiple copies of an entry (one for each future scheduled update):

  1. duplicate the product entry (call this A) you want to update (lets call the duplicate B)
  2. set the end date of A and the start date of B to be the time you want the update to happen
  3. make the changes you want to happen as part of the update in B

Another possible way to accomplish this is to have:

  • a Product entry containing
    • fields which are not part of the scheduled updates (e.g., the product title and SKU always stays the same; if they need change, this would represent a new product)
    • a multi-reference field to a Product Details content type
  • The Product Details entry(-ies) containing:
    • the fields which are possible to update
    • a Publish Date/Time representing when to publish the particular Product Details entry and when to unpublish all other Product Details entries referenced from the parent Product entry

Both methods could make use of the Contentful Scheduler tool to perform the publishing and unpublishing. The second method would require a little change in the logic of the scheduler:

  • it would have to use the links_to_entry search parameter to find the parent Product entry which references it
  • unpublish all published Product Details entries referenced from the parent Product entry (ideally should only be one entry)
  • publish the Product Details entry with the Publish Date/Time of today/now

With either idea you could use the Preview API to get all future (or past) updates to a particular product or search for the most recent product/product details scheduled update which has a publish date or start date less than a particular date/time.

Hope this helps!

I’m happy to share an update on this topic: Contentful now offers scheduled publishing and tasks! :tada: Check out this blog post for details: Content operations just got easier with scheduled publishing, comments and tasks

The scheduled publishing feature we’ve released so far is just the beginning. We are working on something called Content Variants which will be pretty similar to what you mentioned about “all past and future states of a content item.”