Git Product home page Git Product logo

reshuffle-airtable-connector's Introduction

reshuffle-airtable-connector

Code | npm | Code sample

npm install reshuffle-airtable-connector

Reshuffle Airtable Connector

This package contains a Reshuffle connector to connect Airtable APIs.

The following example exposes an endpoint to return the first page of Airtable tab 'Design projects' with view 'All projects'. After running the example go to http://localhost:8000/projects to view the results.

const { HttpConnector, Reshuffle } = require('reshuffle')
const { AirtableConnector } = require('reshuffle-airtable-connector')

const app = new Reshuffle()

const airtableConnector = new AirtableConnector(app, {
  endpointUrl: 'AIRPOINT_ENDPOINT_URL', // 'https://api.airtable.com'
  apiKey: 'YOUR_API_KEY',
  base: 'YOUR_BASE'
})

const httpConnector = new HttpConnector(app)
const base = airtableConnector.base()

httpConnector.on({ method: 'GET', path: '/projects' }, async (event, app) => {
  base('Design projects').select({
    view: 'All projects'
  }).firstPage(function(err, records) {
    if (err) {
      event.res.json(err)
      return
    }
    event.res.json(records.map(record => record.get('Name')))
  })
})

app.start()

The official Airtable JavaScript library can be found [here]](https://github.com/Airtable/airtable.js)

Table of Contents

Configuration Options

Connector Events

Listening to Airtable events

Connector Actions

Base - Retrieve a base Airtable object

SDK - Retrieve a full Airtable sdk object

Configuration options

const app = new Reshuffle()
const airtableConnector = new AirtableConnector(app, {
  endpointUrl: 'AIRPOINT_ENDPOINT_URL',
  apiKey: 'YOUR_API_KEY',
  base: 'YOUR_BASE'
})

endpointUrlis optional, the default is https://api.airtable.com.

Get your apiKey by following the steps in this article.

More details about the APIs are described in Airtable API documentation.

Events

Listening to Airtable events

In order to listen to events happening in Airtable, you'll need to capture them with the connector's on function, providing an AirtableConnectorEventOptions to it.

Events are specific to an Airtable table/tab, for example in order to define all three events (added, modified, deleted) on two tables you have to define six events.

interface AirtableConnectorEventOptions {
  type: AirtableEventType // See bellow 
  table: string           // Airtable table/tab name
  fireWhileTyping?: boolean // How to manage `RecordModified` events for text fields, check the explanation below. The default value is false.
}

// Where...
type AirtableEventType =
  | 'RecordAdded'
  | 'RecordModified'
  | 'RecordDeleted'

* 'RecordAdded' - For a Grid View, when adding a new record there is no 'Create New' button that opens a dialog that enables populating and saving the record's fields. Instead Airtable stores the new record at the time you click the create the new record, at this stage all the record's fields are empty. Due to that, a 'RecordAdded' event for a Grid View will end up having an empty record.

** fireWhileTyping - Airtable persists every keystroke as the user is typing text. This may result in several 'RecordModified' events firing for a single field change. When fireWhileTyping is false (the default value) the connector will fire an event only when the user stops typing. When fireWhileTyping is true there will be number of events, similar to the way that Airtable persisted the change.

Example:

airtableConnector.on({ type: 'RecordModified', table: 'Design projects' }, async (event, app) => {
  console.log('RecordModified on Design projects table event')
  console.log(event.id)
  console.log(event.fields)
})

Actions

base

Returns a base object providing an access to the Airtable APIs. Usually you will use base in order to execute all the Airtable APIs.

const base = airtableConnector.base()

Example:

const base = airtableConnector.base()

base('Design projects').select({
    view: 'All projects'
  }).firstPage(function(err, records) {
    if (err) {
      event.res.json(err)
      return
    }
    event.res.json(records.map(record => record.get('Name')))
  })

sdk

Usually base will be the main access to the Airtable APIs but if you need the SDK it is available by using this action.

const sdk = airtableConnector.sdk()

Example:

const base = airtableConnector.sdk().base('YOUR_BASE')

base('Design projects').select({
    view: 'All projects'
  }).firstPage(function(err, records) {
    if (err) {
      event.res.json(err)
      return
    }
    event.res.json(records.map(record => record.get('Name')))
  })

reshuffle-airtable-connector's People

Contributors

ashevat avatar dependabot[bot] avatar

Watchers

Avner Braverman avatar James Cloos avatar Nimo avatar  avatar Christophe Gachiniard avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.