PHP wrapper for Airtable API.
Airtable API does not allow to manipulate with bases or with fields in tables. So you must create tables and its fields manually in Airtable interface.
Important
Every base has own documentation where you find base
identificator (starts with app
e.g. appGYr9gxkAk0wKNk
), which is required parameter. API Key
is located in account settings.
The best way to install davidzadrazil/airtable-api-php is using Composer:
$ composer require davidzadrazil/airtable-api-php
First of all, you must initialize Airtable class and Request handler:
$airtable = new DavidZadrazil\AirtableApi\Airtable('API_KEY', 'BASE_ID');
$request = new DavidZadrazil\AirtableApi\Request($airtable, 'TABLE_NAME');
Important: Airtable limits response with maximum 100 records.
$tableRequest = $request->getTable();
do {
foreach ($tableRequest->getRecords() as $record) {
echo $record->getName();
echo $record->getEmail();
echo $record->getAnotherValue();
}
} while ($tableRequest = $tableRequest->nextPage());
getRecords()
returns array of AirtableApi\Record.
Fetching records from table can be used with available parameters like filterByFormula
, maxRecords
, pageSize
, sort
or view
.
$request->getTable(['pageSize' => 50, 'filterByFormula' => '{Name} = "test"']);
$response = $request->createRecord(
[
'Name' => 'This appears in Name field',
'Email' => 'john@doe.com',
'LinkToAnotherTable' => ['recsH5WYbYpwWMlvb']
]
);
$response->isSuccess(); // true / false
$response->getRecords(); // returns newly created record with ID
Updates specific record with given record ID.
$response = $request->updateRecord('recsH5WYbYpwWMlvb', ['Name' => 'Updated value']);
$response->isSuccess(); // true / false
Delete specific record with given record ID.
$response = $request->deleteRecord('recsH5WYbYpwWMlvb');
$response->isSuccess(); // true / false