adding csv writing to api.php