Coder Social home page Coder Social logo

airtable's Introduction

Golang Airtable API

GoDoc Go codecov Go Report Mentioned in Awesome Go

A simple #golang package to access the Airtable API.

Table of contents

Installation

The Golang Airtable API has been tested compatible with Go 1.13 on up.

go get github.com/mehanizm/airtable

Basic usage

Initialize client

You should get your_api_token in the airtable account page

client := airtable.NewClient("your_api_token")

You can use custom http client here

client.SetCustomClient(http.DefaultClient)

Custom context

Each method below can be used with custom context. Simply use MethodNameContext call and provide context as first argument.

List bases

bases, err := client.GetBases().WithOffset("").Do()

Get base schema

schema, err := client.GetBaseSchema("your_database_ID").Do()

Get table

To get the your_database_ID you should go to main API page and select the database.

table := client.GetTable("your_database_ID", "your_table_name")

List records

To get records from the table you can use something like this

records, err := table.GetRecords().
	FromView("view_1").
	WithFilterFormula("AND({Field1}='value_1',NOT({Field2}='value_2'))").
	WithSort(sortQuery1, sortQuery2).
	ReturnFields("Field1", "Field2").
	InStringFormat("Europe/Moscow", "ru").
	Do()
if err != nil {
	// Handle error
}

Add records

recordsToSend := &airtable.Records{
    Records: []*airtable.Record{
        {
            Fields: map[string]interface{}{
                "Field1": "value1",
                "Field2": true,
            },
        },
    },
}
receivedRecords, err := table.AddRecords(recordsToSend)
if err != nil {
	// Handle error
}

Get record by ID

record, err := table.GetRecord("recordID")
if err != nil {
	// Handle error
}

Update records

To partial update one record

res, err := record.UpdateRecordPartial(map[string]interface{}{"Field_2": false})
if err != nil {
	// Handle error
}

To full update records

toUpdateRecords := &airtable.Records{
    Records: []*airtable.Record{
        {
            Fields: map[string]interface{}{
                "Field1": "value1",
                "Field2": true,
            },
        },
        {
            Fields: map[string]interface{}{
                "Field1": "value1",
                "Field2": true,
            },
        },
    },
}
updatedRecords, err := table.UpdateRecords(toUpdateRecords)
if err != nil {
	// Handle error
}

Delete record

res, err := record.DeleteRecord()
if err != nil {
	// Handle error
}

Bulk delete records

To delete up to 10 records

records, err := table.DeleteRecords([]string{"recordID1", "recordsID2"})
if err != nil {
	// Handle error
}

Special thanks

Inspired by Go Trello API

airtable's People

Contributors

mehanizm avatar icurbix avatar charlieegan3 avatar trotterdylan avatar francois2metz avatar pantyukhov avatar srerickson avatar yaroslavrudenko 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.