Contentful logo

Contentful Community

Fields with missing references

Is there a way to filter results based on if a Link field has been linked to a missing (deleted) record?

1 Like

Hi @wes ,

With CDA, when asking linked entries, it is possible to obtain the UNRESOLVABLE_LINK error, that would tell which entries are missing/deleted. You might then need to delete the link via CMA (at the error or programmatically).

Hello,

Yes I was expecting something like “UNRESOLVABLE_LINK” but upon examining the JSON returned entry, the linked field does indeed show an assetID that no longer exists. The only way I can work out if it exists is by doing an extra call. Am I missing something?

Hello!
I am also interested in this question. I really don’t get it, why Contentful CDA fetch missing entries and return errors after that. And there is no any filters to filter by only existing entries

Hi @Alma is there any way to do this?

Hi @wes ,

It’s weird if you don’t get the UNRESOLVABLE_LINK error, maybe because it’s an asset. Would you be able to post here an example of the response you get?

I just get the assetID returned in the linked field. Obviously, if you try to do anything with it, you get a guzzle error (PHP).

So right now, every Entry returned with my linked field has the assetID included, but the state is unknown. Which means I need to do a separate API call to see if the image exists.

Is this expected behaviour?

Hi @wes,

You are right, when querying a single entry, it does not show the unresolvable error. However, you could replace the getEntry, with getEntries with sys.id=entry-id. In that way you will get the error in the response and you would be able to filter-out invalid assets.

https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/equality-operator/query-entries/console/js