Filter out unpublished linked entries

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

1 Like

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?

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.

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

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.

Hi, I just run into the same issue. It would be great if a linked entry with the status “Archived” would not show up in the linking page.

Hello, I’m experiencing a similar issue, though I’m not clear what a referencing item or linked entry would be in my case. I’m using the javascript SDK to retrieve published articles like so:

contentfulClient(isPreview)
    .getEntries({
      include: 1,
      content_type: ContentModels.Article,
      "fields.hasVideo": false,
    })
    .then((entries) => normalizeAndProcessContentfulEntries<any, ArticleFields>(entries))
    .catch((error) => {
      throw new Error(error);
    });

The function normalizeAndProcessContentfulEntries() is expecting certain required fields for a retrieved article to have values, and breaks if they don’t exist. The problem that I am seeing is that if I use the Contentful UI to start drafting a new article entry, the partially-drafted entry is included in the query response, causing errors.

Is there any way that I can prevent non-published articles from being returned in the getEntries() response?

Just following up here. For us, we were accidentally using the preview client for some of our queries, which of course has access to unpublished data.