### Airtable.js Quick Start Example Source: https://github.com/airtable/airtable.js/blob/master/_autodocs/README.md Demonstrates basic usage of the Airtable.js library, including configuration, accessing a base and table, creating, querying, updating, and deleting records. ```javascript const Airtable = require('airtable'); Airtable.configure({ apiKey: 'YOUR_API_KEY' }); const base = Airtable.base('appXXXXXX'); const table = base('TableName'); const records = await table.create([ { Name: 'Alice', Email: 'alice@example.com' }, { Name: 'Bob', Email: 'bob@example.com' } ]); const results = await table.select({ filterByFormula: "{Status} = 'Active'", sort: [{ field: 'Name', direction: 'asc' }] }).all(); await records[0].patchUpdate({ Status: 'Active' }); await records[0].destroy(); ``` -------------------------------- ### Airtable.js 5-Minute Start Source: https://github.com/airtable/airtable.js/blob/master/_autodocs/START-HERE.md This snippet demonstrates the basic setup and common operations for interacting with Airtable using Airtable.js. It covers API key configuration, base and table selection, and performing create, update, and delete actions. ```javascript const Airtable = require('airtable'); // 1. Configure (or use env var AIRTABLE_API_KEY) Airtable.configure({ apiKey: 'pat...' }); // 2. Get a base const base = Airtable.base('appXXXXXX'); // 3. Get a table const table = base('TableName'); // 4. Do something const records = await table.select().all(); console.log(records.length, 'records'); // 5. Create const created = await table.create({ Name: 'Alice' }); // 6. Update await created.patchUpdate({ Status: 'Active' }); // 7. Delete await created.destroy(); ``` -------------------------------- ### Example Query with Sorting Source: https://github.com/airtable/airtable.js/blob/master/_autodocs/types.md This example demonstrates how to construct a query with multiple sort parameters, ordering records first by 'Name' in ascending order and then by 'Created' in descending order. ```typescript const query = table.select({ sort: [ { field: 'Name', direction: 'asc' }, { field: 'Created', direction: 'desc' } ] }); ``` -------------------------------- ### Install Airtable.js with npm Source: https://github.com/airtable/airtable.js/blob/master/README.md Install the Airtable.js library in your Node.js project using npm. Compatible with Node 10 and above. ```sh npm install airtable ``` -------------------------------- ### Complete Example: Sync Contacts Source: https://github.com/airtable/airtable.js/blob/master/_autodocs/README.md This example demonstrates how to synchronize contact data with Airtable. It fetches existing records, creates new ones, and updates existing ones based on email addresses. ```javascript const Airtable = require('airtable'); // Configure Airtable.configure({ apiKey: process.env.AIRTABLE_API_KEY }); // Define schema const table = Airtable.base('appXXXXXX')('Contacts'); // Example: Sync contacts async function syncContacts(newContacts) { try { // Fetch existing const existing = await table.select().all(); const emails = new Set(existing.map(r => r.fields.Email)); // Create new ones const toCreate = newContacts.filter(c => !emails.has(c.email)); if (toCreate.length > 0) { const created = await table.create( toCreate.map(c => ({ Email: c.email, Name: c.name })) ); console.log(`Created ${created.length} records`); } // Update existing for (const contact of newContacts) { const record = existing.find(r => r.fields.Email === contact.email); if (record && record.fields.Name !== contact.name) { await record.patchUpdate({ Name: contact.name }); } } console.log('Sync complete'); } catch (err) { console.error('Sync failed:', err.message); } } ``` -------------------------------- ### Complete Usage Timeline Source: https://github.com/airtable/airtable.js/blob/master/_autodocs/API-SURFACE.md A step-by-step guide illustrating the typical workflow for using the Airtable.js SDK, from initialization to data manipulation. ```APIDOC ## Complete Usage Timeline 1. **Import** → `const Airtable = require('airtable')` 2. **Configure** → `Airtable.configure({apiKey: '...'})` 3. **Access Base** → `const base = Airtable.base('appXXXXXX')` 4. **Access Table** → `const table = base('TableName')` 5. **Query** → `await table.select({...}).all()` 6. **Create** → `await table.create({...})` 7. **Update** → `await record.patchUpdate({...})` 8. **Delete** → `await record.destroy()` ``` -------------------------------- ### Example RecordData for a Contact Source: https://github.com/airtable/airtable.js/blob/master/_autodocs/types.md This example shows how to create a RecordData object conforming to the ContactFields interface, including a record ID and partial field data. ```typescript const recordData: RecordData = { id: 'recXXXXXX', fields: { Name: 'John Doe', Email: 'john@example.com' }, commentCount: 2 }; ``` -------------------------------- ### Select All Records Source: https://github.com/airtable/airtable.js/blob/master/_autodocs/api-reference/query.md A basic example to select and retrieve all records from a table. Ensure the table name is correctly specified. ```javascript const table = base('Contacts'); const records = await table.select().all(); ``` -------------------------------- ### Initialize Airtable and Load Artists Source: https://github.com/airtable/airtable.js/blob/master/test/test_files/index.html Sets up the Airtable base connection and defines functions for loading and deleting artists. This is the initial setup for the application. ```javascript var Airtable = require('airtable'); var base = new Airtable({ apiKey: 'FILL_OUT_API_KEY' }).base('FILL_OUT_BASE_ID'); var deleteArtist = function(record) { record.destroy(function(err) { if (err) { console.log('Error destroying ', recordId, err); } else { console.log('Destroyed ', record.getId()); $('div[data-record-id="'+record.getId()+'"]\[data-record-id="'+record.getId()+'"].remove(); } }); }; var loadArtists = function() { $('#artists').empty(); base('Artists').select({ sort: [ {field: 'Name', direction: 'asc'} ] }).eachPage(function page(records, fetchNextPage) { records.forEach(function(record) { console.log('Retrieved ', record.get('Name')); var $artistInfo = $('
'); $artistInfo.append($('

').text(record.get('Name'))); $artistInfo.append($('
').text(record.get('Bio'))); var x = $('