Oct 16, 2020 11:23 AM
Here’s my thinking. I like the simplicity of Airtable’s own “Export CSV” function. Data in a spreadsheet as a simple backup is all I am after.
If “Export CSV” could be triggered via a script, the entire process could be automated. A new record could be the trigger to run this script.
Does anyone know if this is even possible?
Thank you!
Oct 24, 2020 12:17 AM
@Markus_Wernig This could be made possible with an Airtable App with a few options like whether you want the ids or resolve the relationships instead.
Still gotta be done, but that could be a great way of making it available for everyone, and for free.
May 25, 2021 09:29 AM
Yes to the CSV, It really should be a simple trigger, or even a googlesheets function, which you can kind of work into by playing the triggers that execute when all fields that have are no blank. Not ideal, but it can kind of work.
Ideally a secondary CSV back-up nightly automation is needed.
Further, a airtable file, that supports records IDs etc would be most appreciated.
Oct 21, 2021 02:57 AM
For anyone wanting live csv export by api endpoint, here is an endpoint i built:
https://csv-getter-for-airtable.ew.r.appspot.com/all-csv?bid=<your_base_id>&apik=<your_api_key>&tname=<your_table_name>
Details can be found here
Apr 07, 2022 11:59 AM
Above has been deprecated. Much easier to use now by going here
Oct 05, 2022 02:02 AM
This is amazing! Thanks so much :slightly_smiling_face:
Oct 20, 2022 12:59 AM
So, I changed my mind and eventually build a “print-base-structure” airtable app. Then, I use a diff tool to compare the generated output, and it allows me to see what structural differences there are between two bases.
cool thanks
btw, within script extension you can work across the tables of one base, you probably know but do you have any recommendation of how to export or create a new table from a list of records re-arranged and coming from different tables ?
Nov 02, 2023 08:43 PM
Hello! I'd love to know how to do that if you're willing to share
Thanks!
Sep 23, 2024 10:21 AM
Hi Kuovonne,
How would one use scripting to convert the existing data into a csv format? I tried with the below, but couldn't get the URL.createObjectURL to work with Airtable.
@kuovonne wrote:You cannot trigger the existing “Download CSV” feature in Airtable with a script. However, it is possible to use scripting (either in scripting app, or with an automation scripting action) to convert the existing data to CSV format and save that data to a website. The exact details would depend on where you want to save the data.
// Define the input variables
let table = base.getTable("Content Brief"); // Table name
let view = table.getView("Excel Author Flyer Download View"); // View name
// Fetch records from the specified view
let result = await view.selectRecordsAsync();
let records = result.records;
// Check if there are records to process
if (records.length === 0) {
console.log("No records found in the view.");
return;
}
// Convert records to CSV format
function recordsToCSV(records, fields) {
if (records.length === 0) return '';
// Map field names from the result fields
const headers = fields.map(field => field.name);
const csvRows = [];
// Add header row
csvRows.push(headers.join(','));
// Add data rows
for (let record of records) {
const values = headers.map(header => {
const value = record.getCellValue(header);
return `"${String(value || '').replace(/"/g, '""')}"`; // Escape quotes
});
csvRows.push(values.join(','));
}
return csvRows.join('\n');
}
// Fetch the field names for the table/view
const fields = table.fields;
const csvContent = recordsToCSV(records, fields);
// Check if the CSV content is empty
if (!csvContent) {
console.log("CSV content is empty.");
return;
}
// Create a file blob from the CSV content
const blob = new Blob([csvContent], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
// Output the download link
output.markdown(`Download your CSV file [here](${url}).`);
// Clean up the URL object after use
setTimeout(() => {
URL.revokeObjectURL(url);
}, 1000);