Cmdlets for Airtable

Build 21.0.7930

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our Airtable Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Installing and Connecting

If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.

Install-Module AirtableCmdlets

The following line is then added to your profile, loading the cmdlets on the next session:

Import-Module AirtableCmdlets;

You can then use the Connect-Airtable cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-Airtable -APIKey "keymz3adb53RqsU" -BaseId "appxxN2fe34r3rjdG7" -TableNames "TableA,TableB,TableC" -ViewNames "TableA.ViewA,TableA.ViewB,..,TableX.ViewY"

Connecting to Airtable

The Airtable data source only supports the simple token-based authentication method.

To establish a connection begin by locating your ApiKey. You can find this by logging into your Airtable account and navigating to the API section. Then, click Generate API key.

From the same API section, identify your BaseId. Click on Airtable API, or navigate to and select a base.

Supply the following to connect to data:

  • ApiKey: Set this to your API key noted earlier.
  • BaseId: Set this to your Base Id noted earlier. 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.

You may also optionally specify the following to further refine data access:

  • ViewNames: A comma separated list of views in the format TableA.ViewA,TableA.ViewB,..etc. These are the same names of the views as found in the UI.

Important note : '.' character is not suggested to be used for column names since it is used for bulding column names based on paths and may risk breaking INSERT/UPDATE statements. If you already have column names that contain '.' character, please set PathDelimiter connection property to a character that is not used in column names. PathDelimiter is equal to '.' by default.

  • PathDelimiter: The character which will be used as delimiter for bulding column names based on paths.

Retrieving Data

The Select-Airtable cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-Airtable -Connection $conn -Table "SampleTable_1" -Columns @("Id, Column1") -Where "Column2='Bob'"
The Invoke-Airtable cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-Airtable -Connection $conn -Table SampleTable_1 -Where "Column2 = 'Bob'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\mySampleTable_1Data.csv -NoTypeInformation

You will notice that we piped the results from Select-Airtable into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

PS C:\> $conn  = Connect-Airtable -APIKey "keymz3adb53RqsU" -BaseId "appxxN2fe34r3rjdG7" -TableNames "TableA,TableB,TableC" -ViewNames "TableA.ViewA,TableA.ViewB,..,TableX.ViewY"
PS C:\> $row = Select-Airtable -Connection $conn -Table "SampleTable_1" -Columns (Id, Column1) -Where "Column2 = 'Bob'" | select -first 1
PS C:\> $row | ConvertTo-Json
  "Connection":  {

  "Table":  "SampleTable_1",
  "Columns":  [

  "Id":  "MyId",
  "Column1":  "MyColumn1"

Deleting Data

The following line deletes any records that match the criteria:

Select-Airtable -Connection $conn -Table SampleTable_1 -Where "Column2 = 'Bob'" | Remove-Airtable

Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Airtable, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MySampleTable_1Updates.csv | %{
  $record = Select-Airtable -Connection $conn -Table SampleTable_1 -Where ("Id = `'"+$_.Id+"`'")
    Update-Airtable -Connection $conn -Table SampleTable_1 -Columns @("Id","Column1") -Values @($_.Id, $_.Column1) -Where "Id  = `'$_.Id`'"
    Add-Airtable -Connection $conn -Table SampleTable_1 -Columns @("Id","Column1") -Values @($_.Id, $_.Column1)

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930