Simple golang airtable API wrapper

Overview

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")

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

Issues
  • Allow setting the baseURL of clients

    Allow setting the baseURL of clients

    This allows clients to be pointed at local test servers in tests to mock responses to Airtable API calls.

    Signed-off-by: Charlie Egan [email protected]

    opened by charlieegan3 3
  • Make WithSort arg field names public

    Make WithSort arg field names public

    Field names on the anonymous struct for WithSort should be public. Otherwise callers in other packages cannot assign to the private fields and calling WithSort results in errors like this:

    cannot use sortQuery (variable of type struct{fieldName string; direction string}) as struct{fieldName string; direction string} value in argument to config.WithSort (IncompatibleAssign)
    
    opened by trotterdylan 2
  • Feature/put post

    Feature/put post

    A PATCH request will only update the fields you specify, leaving the rest as they were. A PUT request will perform a destructive update and clear all unspecified cell values. Need add PUT and PATCH support due Airtables documents. POST cannot be used to update records: To create new records, issue a POST request.

    opened by yaroslavrudenko 2
  • Add records example not working

    Add records example not working

    Not a bug exactly but I can't seem to get the 'Add records' example to work. Got as far to find out that the map[string]interface is missing {} after it in order for the code to compile properly but that is as far I've gotten with my basic Go knowledge. 'Get record by ID' works fine so it's not my credentials/base. Anyone seeing what is missing here or am I overlooking something crucial?

    documentation 
    opened by freekdegreef 2
  • UpdateRecordPartial does not update a partial record. Will update the whole record.

    UpdateRecordPartial does not update a partial record. Will update the whole record.

    When I try to use UpdateRecordPartial by passing a map[string]interface{} with a subset of fields filled in, the Airtable data will have everything erased Except for the fields filled in.

    Btw, thanks for that Offset fix that was pushed 4 days ago; it was impeccably timed.

    opened by tamsanh 2
  • Authorization failing

    Authorization failing

    I'll start off by saying that I'm a fairly new Go programmer, so the fault might be mine :)

    I've got a trivial chunk of code here:

        if (len(os.Args) != 2) {
            fmt.Printf("Arg count is %d, should be 2\n", len(os.Args))
            os.Exit(1)
        } else {
            APIkey := os.Args[1]
            fmt.Printf("Ok, using API key %s\n", APIkey)
        }
    
        guid := guuid.New()
        fmt.Printf("GUID: %s\n", guid)
    
        atClient := airtable.NewClient(APIkey)
        agentsTable := atClient.GetTable(baseID, "Agents")
        newAgentRecord := &airtable.Record{
            ID: guid.String(),
        }
    
        newAgentRecords := &airtable.Records{
            Records: []* airtable.Record {
                newAgentRecord,
            },
        }
    
        _, err2 := agentsTable.AddRecords(newAgentRecords)
        if err2 != nil {
            fmt.Printf("Welp, couldn't register. %s\n", err2)
            os.Exit(1)
        }
    

    APIkey is copy/pasted from my accounts page and matches what I get in the base API docs. Same for baseID. When I run this, I get this output:

    Ok, using API key (redacted)
    GUID: 9328ca10-2539-45fa-a19f-30b53487958c
    Welp, couldn't register. status 401, err: HTTP request failure on /v0/(my base ID)/Agents with status 401
    Body: {"error":{"type":"AUTHENTICATION_REQUIRED","message":"Authentication required"}}
    exit status 1
    

    That GUID changes on every run, of course.

    Any idea what could be going wrong here? I'm using go version go1.15.6 darwin/amd64 installed via Homebrew , with your library installed via go get yesterday.

    opened by BillWeiss-at 1
Releases(v0.2.6)
Owner
mehanizm
Yet another product manager
mehanizm
The NVD API is an unofficial Go wrapper around the NVD API.

NVD API The NVD API is an unofficial Go wrapper around the NVD API. Supports: CVE CPE How to use The following shows how to basically use the wrapper

Lucas TESSON 3 May 9, 2022
A Wrapper Client for Google Spreadsheet API (Sheets API)

Senmai A Wrapper Client for Google Spreadsheet API (Sheets API) PREPARATION Service Account and Key File Create a service account on Google Cloud Plat

ytnobody / satoshi azuma 0 Nov 5, 2021
A complete and simple wrapper for the Hypixel API

Gopixel A simple and complete1 wrapper for the hypixel API Key features Full API coverage1 Autocomplete for fields Near complete structs MIT license I

null 4 Apr 26, 2022
Simple-Weather-API - Simple weather api app created using golang and Open Weather API key

Simple Weather API Simple weather api app created using golang and Open Weather

Siva Prakash 3 Feb 6, 2022
This is a Golang wrapper for working with TMDb API. It aims to support version 3.

This is a Golang wrapper for working with TMDb API. It aims to support version 3. An API Key is required. To register for one, head over to themoviedb

Cyro Dubeux 52 May 18, 2022
⚡️ SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang)

Gosip - SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang) Main features Unattended authentication using different strategies

Andrew Koltyakov 73 May 10, 2022
A small, fast, reliable pastemyst API wrapper written in Golang

A small, fast, reliable pastemyst API wrapper written in Golang. Official pastemyst API docs found here.

null 11 Nov 18, 2021
SpamProtection-Go is an Official golang wrapper for Intellivoid SpamProtection API

SpamProtection-Go is an Official golang wrapper for Intellivoid SpamProtection API, which is fast, secure and requires no additional packages to be installed.

Intellivoid 0 Feb 26, 2022
Unofficial Anilist.co GraphQL API wrapper for GoLang.

anilistWrapGo Unofficial Anilist.co GraphQL API wrapper for GoLang. Examples All examples are present as tests in test directory. Below are a few snip

ダンクデル (Sayan Biswas) 14 Feb 17, 2022
Pterodactyl API wrapper written in Golang

WARNING That repository isn't available for production environment. Many endpoints aren't yet implemented. Be careful if you are using that module. pt

Luiz Otávio de Farias Correa 3 Mar 28, 2022
A Wrapper of the Piston API in Golang

Go-Piston! This is a Go wrapper for working with the Piston API. It supports both the endpoints, namely runtimes and execute, mentioned here. ?? Insta

null 7 Feb 20, 2022
Golang wrapper for the FiveM natives API

Golang wrapper for the FiveM natives API

normalM 3 Nov 20, 2021
Golang API wrapper of OkEX

A complete golang wrapper for Okex V5 API. Pretty simple and easy to use. For more info about Okex V5 API read here.

Amir 25 May 19, 2022
Golang wrapper for the Sylviorus antispam API for telegram

Syl-Go Golang wrapper for the Sylviorus antispam API for telegram package test

Pranav Ajay 1 Jan 2, 2022
Gocaptcha - An API wrapper for popular captcha solvers such as AntiCaptcha and 2Captcha in Golang

An API wrapper for popular captcha solvers such as AntiCaptcha and 2Captcha in Golang

null 14 Apr 27, 2022
Trello API wrapper for Go

Go Trello API A #golang package to access the Trello API. Nearly 100% of the read-only surface area of the API is covered, as is creation and modifica

Aaron Longwell 199 Apr 13, 2022
null 86 May 3, 2022
The fantastic Reddit API wrapper for gophers

mira is a Reddit Api Wrapper written in beautiful Go. It is super simple to use the bot as we also provide you with simple but fully extensive interfaces. Currently, mira is a project that is considered more or less complete.

Sandy 54 Apr 2, 2022
A Telegraph API wrapper in Go

Telegra.ph is a minimalist publishing tool that allows you to create richly formatted posts and push them to the Web in just a click. Telegraph posts also get beautiful Instant View pages on Telegram. So, this Go wrapper enables you to do all that easily.

Anony 23 May 16, 2022