Contentful.com API Order / Sort Request

For those with experience using the contentful.com API, I'm trying to query and sort the field name and currently get a "ServerError". An example of a request created against their example API (with the parameter "fields.name"):

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 rather vague ( https://www.contentful.com/developers/documentation/content-delivery-api/javascript/#search-order ), and I searched for examples / samples for a long time, but to no avail.

Thanks for any thoughts / ideas!

+5
source share
1 answer

I'm a frontman engineer at Contentful.
If you want to order records by a specific field, you need to limit the search to the content type by passing the request parameter content_type . This is because the field you want to sort may not exist in all of your records. Example:

 https://cdn.contentful.com/spaces/cfexampleapi/entries?order=fields.name&content_type=cat&access_token=b4c0n73n7fu1 

Note that this example still does not work, because the name field is of type Text (full text). Full-text fields support full-text search, but are not ordered. Instead, you can use the Symbol field. Characters maintain order, but not full-text search.

This, for example, will work since color is a character field:

 https://cdn.contentful.com/spaces/cfexampleapi/entries?order=fields.color&content_type=cat&access_token=b4c0n73n7fu1 
+9
source

Source: https://habr.com/ru/post/1205328/


All Articles