Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
185
rated 0 times [  186] [ 1]  / answers: 1 / hits: 5826  / 10 Years ago, thu, october 23, 2014, 12:00:00

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!


More From » contentful

 Answers
16

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

[#41739] Tuesday, October 21, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
davion

Total Points: 458
Total Questions: 109
Total Answers: 100

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;