Download the PHP package guym4c/airtable-client without Composer
On this page you can find all versions of the php package guym4c/airtable-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download guym4c/airtable-client
More information about guym4c/airtable-client
Files in guym4c/airtable-client
Package airtable-client
Short Description PHP Airtable API client
License MIT
Homepage https://github.com/guym4c/airtable-client
Informations about the package airtable-client
airtable-client
A modern PHP API client for Airtable.
Install
via Composer:
Usage
Get yourself an instance of the client:
You can now access CRUD (create, read, update, delete) operations on the tables in your base.
Records
The client will provide an instance of a Record
after Get, Create and Update operations. Record
exposes getters for the table it is in, its Airtable ID, the JSON data array, and the time that it was fetched from Airtable.
You can also access fields in the record as properties of the Record
:
Where your Airtable field names have spaces in, you can use the curly brace syntax - $record->{'field name with spaces'};
.
Fields that relate to other tables in the base are automatically detected. If you are accessing the field as a property, the client does not know which table the relation is directed towards, and will return you a Loader
that you can pass the table name to and resolve the relation.
You can also just call $record->load($field, $table);
to get straight to the related record.
Listing records
You can get more than 1 record by calling $airtable->list($table)
. You can filter these results by passing an extra Filter
parameter - see your base's API docs for details on what the properties of Filter
do.
There are two filter shorthand methods: search($table, $field, $value)
and find($table, $field, $value)
. search()
performs an Airtable search for $value
in $table
.$field
, and as such will return substring matches. find()
will only return exact matches.
As list()
results are paginated, list()
returns the completed Request
object to you. You can then either get the list of Record
s that were fetched using getRecords()
, or move to the next page using nextPage()
. Bear in mind that the page pointer will eventually reset on Airtable's end.
Batch jobs
$airtable->createAll()
and $airtable->updateAll()
allow requests to be batched. You can pass as many arrays and records to these methods respectively, and the client will use batch requests to create them all.
Rate limits
Airtable's API is rate-limited to 5 queries per second. If you exceed this limit, the client will throttle requests, blocking as it does. If this rate is exceeded on Airtable's end and you are put into the 30-second penalty box, calls to the API will raise an exception.
Caching
Commonly, you may have some tables within your base where data is more stagnant. To prevent these from affecting your rate limit, you may provide the client constructor an implementation of the Doctrine Cache interface, and an array of tables you consider 'cachable'.
The client will respond to requests that have no filters or sorts applied from the cache, and attempt to respond to get()
, search()
and find()
too. You can clear the cache by calling the client's flushCache()
method. A table's cache will also be dropped when records are created, modified or deleted by the client.
Cachable tables must have less than 101 records, as the client will not cache tables that Airtable paginates.
Advanced
The client constructor exposes additional parameters for advanced usage.
$key
(required): API key$baseId
(required): Airtable base ID$cache
: Doctrine Cache instance$cachableTables
: Tables that are cached by the client$apiEndpoint
: An API endpoint to use as an alternative to the official Airtable API endpoint. Must include the version path.$headers
: Associative array of headers to append to requests$isRateLimited
: Whether to enforce the Airtable rate limit (defaulttrue
)
If you are using the client across multiple applications, you may come up against the rate limit if your clients all attempt to contact Airtable at once. The last three constructor parameters are provided to enable you to proxy requests to Airtable through a central throttle.
All versions of airtable-client with dependencies
ext-json Version *
davedevelopment/stiphle Version ^0.9.2
shrikeh/teapot Version ^2.3
doctrine/cache Version ^1.8