PHP code example of sleiman / airtable-php

1. Go to this page and download the library: Download sleiman/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/ */

    

sleiman / airtable-php example snippets






use \TANIOS\Airtable\Airtable;
$airtable = new Airtable(array(
    'api_key' => 'API_KEY',
    'base'    => 'BASE_ID'
));

$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);

// 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 protected]',
);

// 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);

$update_contact_details = array(
	'Telephone #' => '514-123-2942',
);
$update_contact = $airtable->updateContent("Contacts/{entry-id}",$update_contact_details);
print_r($update_contact);

$expended = $airtable->getContent( "Customers/recpJGOaJYB4G36PU", false, [
    'Customer Details'
] );

$expended = $airtable->getContent( "Customers/recpJGOaJYB4G36PU", false, [
    'Field Name' 	        => 'Table Name',
    'Customer Meetings'  => 'Meetings'
] );

$expend_expended = $airtable->getContent( "Customers/recpJGOaJYB4G36PU", false, [
    'Customer Details',
    'Meetings'      => [
        'table'     => 'Meetings',
        'relations' => [
            'Calendar'  => 'Calendar',
            'Door'      => [
                'table'         => 'Doors',
                'relations'     => [
                    'Added By'  => 'Employees'
                ]
            ]
        ]
    ]
] );

$delete_contact = $airtable->deleteContent("Contacts/{entry-id}");

$check = $airtable->quickCheck("Contacts",$field,$value);

$check = $airtable->quickCheck("Contacts","Email","[email protected]");
if($check->count > 0){
    // the value is already there
    var_dump($check->records);
} else {
    // it's not there
}

$content = $a->saveContent( 'Links', [
    [
        'fields'            => [
            'Name'          => 'Tasty'
        ]
    ],
    [
        'fields'            => [
            'Name'          => 'Yolo'
        ]
    ]
] );

$update = [];

foreach ( $content->records as $record )
{
    $update[] = [
        'id'            => $record->id,
        'fields'        => [
            'Slug'      => strtolower( $record->fields->Name )
        ]
    ];
}

$response = $a->updateContent( 'Links', $update );

$delete = [];

foreach ( $response->records as $record )
{
    $delete[] = $record->id;
}

$response = $a->deleteContent( 'Links', $delete );

composer