Home Airtable Development ( API Overview ) Part 1
Post
Cancel
Preview Image

Airtable Development ( API Overview ) Part 1

Greetings

Welcome, in this note, I will simply be covering the important aspect of the Airtable API and important and advanced Airtable features worth mentioning.

base

base basically refers to ‘Database’ in Airtable, it’s the storage that contains your information. The base has access to list of tables.

1
2
console.log(`The name of my base is ${base.name}.`);
console.log(`It contains ${base.tables.length} tables.`);

Documentation

cursor

A cursor contains information about the active table and active view

let tableId = cursor.activeTableId;

Table

Table represents each table in your base. You can use it to find all of the views, fields, and records it contains. Each base has at least one table.

View

A view belonging to a table in your base. Each table has at least one view.

let table = base.getTable("Tasks");
let view = table.getView("Todo");
console.log(view);
Field

A field belonging to a table in your base. Each table has at least one field.

let table = base.getTable("Tasks");
let field = table.getField("Description");
console.log(field);
RecordQueryResult

A RecordQueryResult represents a set of records. It’s a little bit like a one-off Airtable view: it contains a bunch of records, those records can be sorted according to your specification, and just like a view, you can either have all the fields in a table available, or you can just ask for the fields that are relevant to you.

// query for all the records in a table
let table = base.getTable("Tasks");
let queryResult = await table.selectRecordsAsync({
    sorts: [
       // sort by "Description" in ascending order
       {field: "Description"},
       // then by "Priority" in descending order.
       {field: "Priority", direction: "desc"},
    ]
});
// print ID & "Description" from each record:
for (let record of queryResult.records) {
    console.log(`
**${record.id}**
${record.getCellValueAsString("Description")}
`);
}

Interactive Controls in Airtable

Inputs

textAsync

A prompt in the scripting section for accepting input Input Controls

buttonAsync

A button for rendering specific actions based on the selection Button Image

1
2
3
4
5
6
let catOrDog = await input.buttonsAsync('Cats or dogs?', ['Cats!', 'Dogs!']);
if (catOrDog === 'Cats!') {
    output.text('Meow');
} else {
    output.text('Woof');
}

tableAsync

This show a table for you yo select from Button Image

1
2
3
let table = await input.tableAsync('Pick a table');
let result = await table.selectRecordsAsync();
output.text(`There are ${result.records.length} records in '${table.name}'.`);

Field

This prompts the user to select a specific field in the View/Base

1
2
3
let table = base.getTable("Projects");
let field = table.getField("Category");
console.log(`Field id: ${field.id}`);

Other APIs

Config

Configuration settings for the script

fileAsync

Allows you select a file and perform actions e.g CSV Import, XML etc.

output

Your scripting app can output rich information to show your users what’s happening while your script runs, or to display custom analysis of the data in your base. Output is done through the built-in output object.

1
output.text('Hello, world!');
This post is licensed under CC BY 4.0 by the author.

Airtable Development ( Scripting )

Airtable + Forms ( Creating a Questionaire)

Comments powered by Disqus.