PHP code example of armetiz / airtable-php

1. Go to this page and download the library: Download armetiz/airtable-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

armetiz / airtable-php example snippets


$key   = "APP_KEY"; // Generated from : https://airtable.com/account
$base  = "BASE_ID"; // Find it on : https://airtable.com/api
$table = "TABLE_NAME"; // Find it on : https://airtable.com/api

$airtable = new Airtable($key, $base);

$records = $airtable->findRecords($table);

$key   = "APP_KEY"; // Generated from : https://airtable.com/account
$base  = "BASE_ID"; // Find it on : https://airtable.com/api
$table = "TABLE_NAME"; // Find it on : https://airtable.com/api

$airtable = new Airtable($key, $base);

$records = $airtable->findRecords($table);

use Armetiz\AirtableSDK\Airtable as AirtableClient;

class MemberIndex
{
    private $airtable;

    public function __construct(AirtableClient $airtableClient, string $table)
    {
        $this->airtable = $airtableClient->createTableManipulator($table);
    }

    public function clear()
    {
        $this->airtable->flushRecords();
    }

    public function save(array $data)
    {
        $criteria = ["Id" => $data["id"]];
        $fields   = [
            "Id"                    => $data["id"],
            "Firstname"             => $data["firstName"],
            "Lastname"              => $data["lastName"],
            "Email"                 => $data["email"],
            "CreatedAt"             => (string)$data["createdAt"],
        ];

        if ($this->airtable->containsRecord($criteria)) {
            $this->airtable->updateRecord($criteria, $fields);
        } else {
            $this->airtable->createRecord($fields);
        }
    }

    public function delete($id)
    {
        $this->airtable->deleteRecord(["Id" => $id]);
    }
}
 bash
composer