Added ordering by id to apis

Without this for rows that have equal dates some undefined order occurred.