API: Filter lists of IDs before sending them to the database