Add query CRUD and consolidate to api.php