contentfulcontentful-api

Contentful API query for entries that do not have a tag


Is there a way to query for entries that don't have a specific tag?

As per the docs to get a collection of entries based with a set of tags we can use metadata.tags.sys.id[all]=tagA,tagB

e.g.

/spaces/yadj1kx9rmg0/environments/staging/entries?access_token=fdb4e7a3102747a02ea69ebac5e282b9e44d28fb340f778a4f5e788625a61abe&metadata.tags.sys.id[all]=tagA,tagB

or we can get a collection of entries that have at least one tag from a list like this metadata.tags.sys.id[in]=tagA,tagB

e.g.

/spaces/yadj1kx9rmg0/environments/staging/entries?access_token=fdb4e7a3102747a02ea69ebac5e282b9e44d28fb340f778a4f5e788625a61abe&metadata.tags.sys.id[in]=tagA,tagB 

The 'exists' query appears to test for the existence of any tags metadata.tags[exists]=true not a specific tag.

Is there a way to get a collection that doesn't contain a tag? For example to get all entries except those that have the 'featured' tag.


Solution

  • This can be done with nin like this: metadata.tags.sys.id[nin]=tagA,TagB

    It will return items which do not have one or more of the comma separated tags you supply.