Znote (recipes)
  Get Znote  

📊 Airtable Integration

How to use the Airtable Plugin with CRUD

 

📊 Airtable Integration

Seamlessly integrate and manage data in an Airtable spreadsheet. 👉 Ensure you have installed the 🧩 Airtable plugin

⚙️ Initialization

🔑 1. Create and Save Your API Token

📌 Create an Airtable Token Scopes Required:

  • data.records:read
  • data.records:write
  • schema.bases:read
  • schema.bases:write

Access: Your workspace

📋 2. Understanding Airtable URLs

Your Airtable URL follows this structure:

https://airtable.com/BASE/TABLE/VIEW
Example: https://airtable.com/appnXXXX/tblXXXX/viwXXX

🛠 Usage

✏️ Set Your Airtable Credentials

Copy your Airtable details into the block below:

const BASE = "appnXXXX";  // Base ID
const TOKEN = "XXXXXXXX"; // API Token
const TABLE = "tblXXX";   // Table ID

📌 Operations

📑 Create a Table

📖 Field Types Documentation

const AirtableApi = require("./airtable-api.js");

const data = {
  "name": "Purchases",
  "description": "List of customers for downloadable content",
  "fields": [
    { "name": "Email", "type": "email" },
    { "name": "purchaseDate", "options": { "dateFormat": { "format": "YYYY-MM-DD", "name": "iso" } }, "type": "date" },
    { "name": "nbrOfDownload", "options": { "precision": 0 }, "type": "number" },
    { "name": "version", "options": { "precision": 0 }, "type": "number" }
  ]
};

const airtable = new AirtableApi(TOKEN, BASE);
printJSON(await airtable.createTable(data));

📜 List Records

const AirtableApi = require("./airtable-api.js");
const airtable = new AirtableApi(TOKEN, BASE);

const result = await airtable.listRecords(TABLE, 100, 0);
// Alternative: Sort by purchaseDate
// const result = await airtable.listRecordsSorted(TABLE, 100, 0, "purchaseDate");

printJSON(result);

🔍 Search for a Record

📖 Formula Reference

const AirtableApi = require("./airtable-api.js");
const airtable = new AirtableApi(TOKEN, BASE);

const result = await airtable.searchRecord(TABLE, 'SEARCH(SUBSTITUTE("usermail@gmail.com","+","%2B"), {email})');
printJSON(result);

🆕 Create a New Record

const AirtableApi = require("./airtable-api.js");
const airtable = new AirtableApi(TOKEN, BASE);

const creationDate = new Date().toISOString().split('T')[0];

const data = {
  "records": [
    {
      "fields": {
        "Email": "usermail@gmail.com",
        "purchaseDate": creationDate,
        "nbrOfDownload": 0,
        "version": 1
      }
    }
  ]
};

const result = await airtable.createRecord(TABLE, data);
printJSON(result);

✏️ Update a Record

const AirtableApi = require("./airtable-api.js");
const airtable = new AirtableApi(TOKEN, BASE);

const RECORD_ID = "rech8grvSTiksocGa"; // Change to the actual record ID

const data = {
  "fields": {
    "nbrOfDownload": 1
  }
};

const result = await airtable.updateRecord(TABLE, RECORD_ID, data);
printJSON(result);

You're now ready to manage Airtable data directly from Znote! 🚀

Related recipes