Contentful logo

Contentful Community

Filter out unpublished linked entries

#1

I’m using the content delivery API for a production web app. We ran into the issue where somebody unpublished an entry and caused our app to break.

When fetching entries, is it possible to only receive published entries? This would mean that all linked entries would also only show up if they were published.

Thank you,

Bez

#2

Just to give you some more context, in order to recreate the issue I am facing, I created a content-type called Test. A Test has many Brands. I am fetching all entries that have a content-type of Test. When I un-publish one of the brands, the response comes back with one error in the errors array. The sys.id of that error is notResolvable.

Even though I am receiving an error, the items array still comes back populated. However, none of the brands have the fields property.

It would be beneficial for me to render only the data thats is published rather than not rendering anything at all. Is is possible to only fetch published entries?

#3

Hi Bez,

Although the CDA will only retrieve items that are already published, it will still fetch the IDs of referencing items that might be on draft or not available in any way.

There is not a way to directly overcome this behavior but you could delete or publish those that are still not being resolved.

#4

Thanks @gabriel. What’s the reason that the ids are still returned if the referenced item is unpublished?

#5

The ID values are simply stored as record and separate from the actual content of the child entry. Currently, it is the expected behavior of our APIs but I understand it can be a bit confusing and I’m sending out your feedback to our product team.