Content API - Sort

Hello, Builder IO Team,

I need assistance with something related to sorting with content builder io API.

Context:
Well I have two custom fields in the data model:

  1. lastUpdatedDate
  2. date

Both are manually set from Visual editor and located inside data.
So a sort query by the custom date field looks like this
...&sort.data.date...
or sort by lastUpdatedDate like this
...&sort.data.lastUpdatedDate...

And sorting by one of these two returns the correct results and works perfectly, however, when i try to sort by lastUpdatedDate AND date things get messy and the response is not the expected one.

What i am trying to achieve:
In short i want to sort by lastUpdatedDate AND date simultaneously - something like this &sort.data.lastUpdatedDate=1&sort.data.date=1

using the date as a fallback as the lastUpdatedDate field may or may not be set intentionally.

As a solution I could get all the data for a model and then perform the sorting on the frontend, but i really don’t want to do that. That is why i am hoping that the described above is somehow possible?

1 Like