Automate Airtable Integration Tasks from PowerShell
The CData ADO.NET Provider for Airtable is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Airtable.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Airtable; this tutorial shows how to use the Provider to create, retrieve, update, and delete Airtable data.
Once you have acquired the necessary connection properties, accessing Airtable data in PowerShell can be enabled in three steps.
APIKey, BaseId and TableNames parameters are required to connect to Airtable. ViewNames is an optional parameter where views of the tables may be specified.
- APIKey : API Key of your account. To obtain this value, after logging in go to Account. In API section click Generate API key.
- BaseId : Id of your base. To obtain this value, it is in the same section as the APIKey. Click on Airtable API, or navigate to https://airtable.com/api and select a base. In the introduction section you can find "The ID of this base is appxxN2ftedc0nEG7."
- TableNames : A comma separated list of table names for the selected base. These are the same names of tables as found in the UI.
- ViewNames : A comma separated list of views in the format of (table.view) names. These are the same names of the views as found in the UI.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Airtable\lib\System.Data.CData.Airtable.dll") -
Connect to Airtable:
$conn= New-Object System.Data.CData.Airtable.AirtableConnection("APIKey=keymz3adb53RqsU;BaseId=appxxN2fe34r3rjdG7;TableNames=Table1,...;ViewNames=Table1.View1,...;") $conn.Open() -
Instantiate the AirtableDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Column1 from SampleTable_1" $da= New-Object System.Data.CData.Airtable.AirtableDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.column1 }
Update Airtable Data
$cmd = New-Object System.Data.CData.Airtable.AirtableCommand("UPDATE SampleTable_1 SET Column2='SomeValue' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Airtable.AirtableParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Airtable Data
$cmd = New-Object System.Data.CData.Airtable.AirtableCommand("INSERT INTO SampleTable_1 (Column2) VALUES (@myColumn2)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Airtable.AirtableParameter("@myColumn2","SomeValue")))
$cmd.ExecuteNonQuery()
Delete Airtable Data
$cmd = New-Object System.Data.CData.Airtable.AirtableCommand("DELETE FROM SampleTable_1 WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Airtable.AirtableParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject