Giter VIP home page Giter VIP 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]any{
                "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]any{"Field_2": false})
if err != nil {
	// Handle error
}

To full update records

toUpdateRecords := &airtable.Records{
    Records: []*airtable.Record{
        {
            Fields: map[string]any{
                "Field1": "value1",
                "Field2": true,
            },
        },
        {
            Fields: map[string]any{
                "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

charlieegan3 avatar francois2metz avatar mehanizm avatar pantyukhov avatar srerickson avatar trotterdylan avatar yaroslavrudenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

airtable's Issues

Implement `GetRecordsConfig.DoWithContext`

Hello, thanks for the nice library :)

We use code like:

records, err := table.GetRecords().
		FromView(viewID).
		WithOffset(offset).
		Do()

and we have issue with Do() that calls Table.GetRecordsWithParams which calls Table.GetRecordsWithParamsContext using default context context.Background(). We would like to have option to pass custom context instance.

The request I have is to implement DoWithContext(context.Context) that does just that. I could not find a way to achieve passing context, as in the end GetRecordsConfig.params are private

Adding Options field to Field struct

Hello,

I am currently working on an airtable to pg migration tool called airtabletopg.

I did it from scratch as you will see by calling the API directly and wanted to use your work to let go of all the API implementation.
But I miss the Options field inside the Field structure.

I need the Options field to check whether or not a multipleRecordLinks field has a OneToMany, ManyToOne or ManyToMany relationship.

Would you be inclined to add it ?

Here is the struct I made, not sure if it is the right type though.

Robin,

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?

client.GetBases function does not exist

Hey first off wanted to say thank you for creating and maintaining this package!

I just started using it and found that the function client.GetBases that is found on the read me returns an error of client.GetBases undefined (type *airtable.Client has no field or method GetBases)compiler[MissingFieldOrMethod]

I searched the client.go file and found no traces of the GetBases method. Is there something that I'm missing or was this method never implemented?

Pass custom context.Context?

I don't think it's currently possible to pass a custom context. Would it be possible to add this functionality?

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.

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.