Help

Re: Accessing table's model via API

3521 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Matt_Scheurich
5 - Automation Enthusiast
5 - Automation Enthusiast

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.

8 Replies 8
Paul_Abbott
4 - Data Explorer
4 - Data Explorer

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

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…).

Here’s the deal…

Sam_Cohen
4 - Data Explorer
4 - Data Explorer

I have been able to pull the table names using php /json. (see below)
But my ONLY problem is to always pull the column 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();
Matt_Scheurich
5 - Automation Enthusiast
5 - Automation Enthusiast

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?

There is an API. I know one developer who had access to it, and obviously Zapier uses it too.

At this point I would be very surprised if it will ever see a public release though. All references to it in the public docs are gone too…

Matt_Scheurich
5 - Automation Enthusiast
5 - Automation Enthusiast

Hmm. I got an email notification about a reply to this from @Jordan_Violet, but now the reply on this thread has gone. I tried the info he put in there, however the closest I get to anything is from accessing:

GET https://api.airtable.com/v0/{{base_id}}/meta

… and the response:

{
    "error": {
        "type": "TABLE_NOT_FOUND",
        "message": "Could not find table meta in application {{base_id}}"
    }
}
Jordan_Violet
6 - Interface Innovator
6 - Interface Innovator

Unfortunately they shut down the API from public use.