For anyone who has experience using the contentful.com API, I'm trying to query and sort by field name and currently getting a "ServerError". An example of the query that's being generated against their example API (with "fields.name" as the parameter):
https://cdn.contentful.com/spaces/cfexampleapi/entries?order=fields.name&access_token=b4c0n73n7fu1
Note that if "sys.createdAt" is used it works fine...
https://cdn.contentful.com/spaces/cfexampleapi/entries?order=sys.createdAt&access_token=b4c0n73n7fu1
The documentation is pretty vague (https://www.contentful.com/developers/documentation/content-delivery-api/javascript/#search-order) and I've searched long and hard for examples / samples but to no avail.
Thanks in advance for any thoughts / ideas!
You can use the order parameter when paging through larger result sets to keep ordering predictable. For example, order=sys.createdAt will order results by the time the resource was first published. All content and assets in Contentful belong to a space.
Querying for all entries having a specific field set to something (aka it is existing), you would issue a request like: Contentful is also able to query entries, based on a mathematical comparison operator: This will return all entries with the birthday less or equal then 1980-01-01.
For example, order=sys.createdAt will order results by the time the resource was first published. All content and assets in Contentful belong to a space. You will generally have at least one space for a project, but use separate spaces for testing or staging. Each space has a name, a set of locales, and metadata about the space.
To address this problem, Contentful has introduced a new filtering capability to the APIs, enabling the user to query for content based on the fields of referenced entries. The following query explains how to get all the thriller movie credits in a single API call:
I'm a frontend engineer at Contentful.
If you want to order entries by a certain field, you have to restrict your search to a content type by passing the content_type
query parameter.
This is because the field you want to sort by might not exist in all your entries. Example:
https://cdn.contentful.com/spaces/cfexampleapi/entries?order=fields.name&content_type=cat&access_token=b4c0n73n7fu1
Please note that this example will still not work, because the name
field is of type Text
(Fulltext). Fulltext fields support fulltext-search but no ordering. Instead you could use a Symbol
field. Symbols support ordering but no fulltext-search.
This, for example, would work since color
is a symbol field:
https://cdn.contentful.com/spaces/cfexampleapi/entries?order=fields.color&content_type=cat&access_token=b4c0n73n7fu1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With