Accessing table's model via API


#1

I’m curious if anyone has been able to access a single table’s model via the API.

I can’t find anything in the API documentation that allows it, but I assume it’s possible due to the fact that the API documentation itself is being generated based on the tables’ model/columns defined within an Airtable base.

What I’m trying to do is create a client-side data sanitiser and validator. I’d like to control the relationship between the client and the app. Ensuring the data is formatted correctly is a time saving measure that I can do before submitting to the Airtable API and helps me to provide a nicer smoother experience for users. It should also hopefully let me store valid data offline (which won’t error later when being submitted) to then submit to the Airtable API later when connectivity is available.

Since Airtables can have their model/columns changed easily, fetching the model could also mean automating any migrations or potentially reconcile differences between one version of the API to the other. Who knows if it will really work, but it’d be a cool idea to work on at least.


#2

Did you get anywhere with this? I am trying to do something very similar. Checking for already existing records etc.


#3

Sadly I didn’t. I originally sent an email to Airtable about this and no-one has given me an answer yet there either (the first reply suggested I ask on the community forum…).


#4

Here’s the deal…


#5

I have been able to pull the table names using php /json. (see below)
But my ONLY problem is to pull the field name despite if the field are empty or not.
By default AirTable only allows data that is “not” empty…

Does anyone know how to override this?

<?php
$AIRTABLE_API_KEY = 'key_XXXXXXXXXX';
$AIRTABLE_BASE_ID = 'app_XXXXXXXXX';
$AIRTABLE_TABLE_NAME = 'Your_Table_Name';
$AIRTABLE_PARAMS = '&amp;maxRecords=1&amp;view=All%20Responses'; //Retrieve just one record.
$AIRTABLE_API_URL ='https://api.airtable.com/v0/';

if (($AIRTABLE_API_KEY) && ($AIRTABLE_BASE_ID) && ($AIRTABLE_TABLE_NAME)):

$url =$AIRTABLE_API_URL.$AIRTABLE_BASE_ID."/".$AIRTABLE_TABLE_NAME."?api_key=".$AIRTABLE_API_KEY.$AIRTABLE_PARAMS;

$column_names = array();
$records = array();

$st = ini_get("default_socket_timeout"); // backup current value
ini_set("default_socket_timeout", 5000); // 5 seconds

$data = @file_get_contents($url); 
    if($data === false):
        echo "<strong>Airtable API Connection Error!</strong><br/>There is an error when connecting to AirTable API. Please make sure your Airtable credentials are all correct.";
    else:
        echo "<strong>Success!</strong><br/>You are successfully connected to Airtable's API.";

        //Start process after successful connection.
        ini_set("default_socket_timeout", $st); // restore previous value

      $arrJson = json_decode($data, true);
      $records = $arrJson['records'][0]['fields']; //Drilldown to the fields level

      //Just get the Column Names
      foreach($records as $key => $val):

          $column_names[ $key ] = $key; 

      endforeach;

    endif;
else:

    $column_names = "Please Connect to AirTable first";

endif;
      //Show results in array of data.
      var_dump($column_names);
      die();

#6

I’m finding this a bit hard to grok at the moment. There’s obviously some way to get the table’s model/metadata, as is apparent in the API Documentation being generated per table. However there is not a publicly exposed way to do this.

Is there any way to get an actual Airtable dev to look at this and give us some insight as to why it might not be public, and is there any way we can request this feature?