just some boilerplate for demonstrative purposes and learning how the API works and how to access each field, where and what are the IDs of each table and so on.
Created
March 26, 2023 22:21
-
-
Save fiatjaf/2536370dd381f1e5d7fe448ac0f4d709 to your computer and use it in GitHub Desktop.
overview of an Airtable "base" using Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/mehanizm/airtable" | |
) | |
func main() { | |
client := airtable.NewClient(TOKEN) | |
bases, _ := client.GetBases().WithOffset("").Do() | |
for _, base := range bases.Bases { | |
fmt.Println(base.ID, base.Name, base.PermissionLevel) | |
schema, _ := client.GetBaseSchema(base.ID).Do() | |
for _, table := range schema.Tables { | |
fmt.Println(" table", table.ID, table.Name) | |
fmt.Println(" fields") | |
for _, f := range table.Fields { | |
fmt.Println(" ", f.ID, f.Name, f.Type, f.Description, f.ID == table.PrimaryFieldID) | |
} | |
fmt.Println(" views") | |
for _, v := range table.Views { | |
fmt.Println(" ", v.ID, v.Name, v.Type) | |
} | |
fmt.Println(" records") | |
data := client.GetTable(base.ID, table.ID) | |
records, _ := data.GetRecords().MaxRecords(10000).Do() | |
for _, r := range records.Records { | |
fmt.Println(" ", r.ID) | |
for k, v := range r.Fields { | |
fmt.Println(" ", k, "=>", v) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment