Query API with sort ordering