A PHP wrapper for the Airtable API Edit
A PHP client for the Airtable API. Comments, requests or bug reports are appreciated., (*1)
View examples, (*2)
Please note that Airtable doesn't allow schema manipulation using their public API, you have to create your tables using their interface., (*3)
Once you created your base in the Airtable Interface open the API Docs to get your Base ID., (*4)
, (*5)
The Base ID is a code that starts with 'app' followed by a mix of letter or numbers (appsvqGDFCwLC3I10)., (*6)
If you're using Composer, you can run the following command:, (*7)
composer require sleiman/airtable-php
You can also download them directly and extract them to your web directory., (*8)
If you're using Composer, run the autoloader, (*9)
require 'vendor/autoload.php';
Or include the Airtable.php file, (*10)
include('../src/Airtable.php'); include('../src/Request.php'); include('../src/Response.php');
use \TANIOS\Airtable\Airtable; $airtable = new Airtable(array( 'api_key' => 'API_KEY', 'base' => 'BASE_ID' ));
We are getting all the entries from the table "Contacts"., (*11)
$request = $airtable->getContent( 'Contacts' ); do { $response = $request->getResponse(); var_dump( $response[ 'records' ] ); } while( $request = $response->next() ); print_r($request);
// You don't have to use all the params, they are added as a reference $params = array( "filterByFormula" => "AND( Status = 'New' )", "sort" => array(array('field' => 'Count', 'direction' => "desc")), "maxRecords" => 175, "pageSize" => 50, "view" => "Name of your View" ); $request = $airtable->getContent( 'Contacts', $params); do { $response = $request->getResponse(); var_dump( $response[ 'records' ] ); } while( $request = $response->next() ); print_r($request);
We will create new entry in the table Contacts, (*12)
// Create an array with all the fields you want $new_contact_details = array( 'Name' =>"Contact Name", 'Address' => "1234 Street Name, City, State, Zip, Country", 'Telephone #' => '123-532-1239', 'Email' =>'email@domain.com', ); // Save to Airtable $new_contact = $airtable->saveContent( "Contacts", $new_contact_details ); // The ID of the new entry echo $new_contact->id; print_r($new_contact);
Batch Create now available, documentation available below, (*13)
Use the entry ID to update the entry, (*14)
$update_contact_details = array( 'Telephone #' => '514-123-2942', ); $update_contact = $airtable->updateContent("Contacts/{entry-id}",$update_contact_details); print_r($update_contact);
Batch Update now available, documentation available below, (*15)
The response will include all the information of record linked to from another table. In this example, with a single call, the field "Customer Details" will be filled with relations of "Customer Details" table., (*16)
When you don't pass an associative array, we assume that the field and the table name are the same., (*17)
$expended = $airtable->getContent( "Customers/recpJGOaJYB4G36PU", false, [ 'Customer Details' ] );
If for some reasons the name of the field differs from the name of the table, you can pass an associative array instead., (*18)
$expended = $airtable->getContent( "Customers/recpJGOaJYB4G36PU", false, [ 'Field Name' => 'Table Name', 'Customer Meetings' => 'Meetings' ] );
We heard you like to expend your relationships, so now you can expend your expended relationships. The following is possible., (*19)
$expend_expended = $airtable->getContent( "Customers/recpJGOaJYB4G36PU", false, [ 'Customer Details', 'Meetings' => [ 'table' => 'Meetings', 'relations' => [ 'Calendar' => 'Calendar', 'Door' => [ 'table' => 'Doors', 'relations' => [ 'Added By' => 'Employees' ] ] ] ] ] );
But be aware that loading too many relationships can increase the response time considerably., (*20)
Use the entry ID to delete the entry, (*21)
$delete_contact = $airtable->deleteContent("Contacts/{entry-id}");
Batch Delete now available, documentation available below, (*22)
Find a record or many with one line. It's useful when you want to know if a user is already registered or if the same SKU is used. The response will return "count" and "records"., (*23)
$check = $airtable->quickCheck("Contacts",$field,$value); $check = $airtable->quickCheck("Contacts","Email","jon@wordlco.com"); if($check->count > 0){ // the value is already there var_dump($check->records); } else { // it's not there }
Airtable API now allows to create, update, and delete 10 records per API request., (*24)
Create, (*25)
$content = $a->saveContent( 'Links', [ [ 'fields' => [ 'Name' => 'Tasty' ] ], [ 'fields' => [ 'Name' => 'Yolo' ] ] ] );
Update, (*26)
$update = []; foreach ( $content->records as $record ) { $update[] = [ 'id' => $record->id, 'fields' => [ 'Slug' => strtolower( $record->fields->Name ) ] ]; } $response = $a->updateContent( 'Links', $update );
Delete, (*27)
$delete = []; foreach ( $response->records as $record ) { $delete[] = $record->id; } $response = $a->deleteContent( 'Links', $delete );
Copyright (c) 2019 - Programmed by Sleiman Tanios & Guillaume Laliberté, (*28)