All Projects → sleiman → Airtable Php

sleiman / Airtable Php

Licence: gpl-3.0
A PHP client for the Airtable API

Labels

Projects that are alternatives of or similar to Airtable Php

Pokepy
A Python wrapper for PokéAPI
Stars: ✭ 94 (-18.26%)
Mutual labels:  wrapper
Faker Cli
cli wrapper for fakerjs
Stars: ✭ 104 (-9.57%)
Mutual labels:  wrapper
Discord Rpc
Java Wrapper of the Discord-RPC Library for Discord Rich Presence.
Stars: ✭ 109 (-5.22%)
Mutual labels:  wrapper
Zebra database
A compact, lightweight and feature-rich PHP MySQLi database wrapper
Stars: ✭ 98 (-14.78%)
Mutual labels:  wrapper
Coinbasepro Python
The unofficial Python client for the Coinbase Pro API
Stars: ✭ 1,386 (+1105.22%)
Mutual labels:  wrapper
Zubr
Wrapper library to fix inconsistencies in PHP's core functions
Stars: ✭ 105 (-8.7%)
Mutual labels:  wrapper
Php Mediainfo
PHP wrapper around the mediainfo command
Stars: ✭ 93 (-19.13%)
Mutual labels:  wrapper
Tlaw
The Last API Wrapper: Pragmatic API wrapper framework
Stars: ✭ 112 (-2.61%)
Mutual labels:  wrapper
Clam
Quickly turn command-line applications into RESTful webservices with a web-application front-end. You provide a specification of your command line application, its input, output and parameters, and CLAM wraps around your application to form a fully fledged RESTful webservice.
Stars: ✭ 103 (-10.43%)
Mutual labels:  wrapper
Pymiere
Python for Premiere pro
Stars: ✭ 110 (-4.35%)
Mutual labels:  wrapper
Pokebase
Python 3 wrapper for Pokéapi v2
Stars: ✭ 99 (-13.91%)
Mutual labels:  wrapper
Pynlp
A pythonic wrapper for Stanford CoreNLP.
Stars: ✭ 103 (-10.43%)
Mutual labels:  wrapper
Edafa
Test Time Augmentation (TTA) wrapper for computer vision tasks: segmentation, classification, super-resolution, ... etc.
Stars: ✭ 107 (-6.96%)
Mutual labels:  wrapper
Binance.api.csharp.client
C#.NET client for Binance Exchange API.
Stars: ✭ 98 (-14.78%)
Mutual labels:  wrapper
Pokekotlin
Kotlin (or Java, Scala, etc) client for PokeApi
Stars: ✭ 110 (-4.35%)
Mutual labels:  wrapper
Expressvpn Python
ExpressVPN - Python Wrapper (public IP auto fetch).
Stars: ✭ 94 (-18.26%)
Mutual labels:  wrapper
Quickjspp
QuickJS C++ wrapper
Stars: ✭ 105 (-8.7%)
Mutual labels:  wrapper
Wgpu Rs
Rust bindings to wgpu native library
Stars: ✭ 1,694 (+1373.04%)
Mutual labels:  wrapper
Maxwell
Maxwell is an HTTP client which support for middleware and multiple adapters.
Stars: ✭ 111 (-3.48%)
Mutual labels:  wrapper
Sdl2 nim
Wrapper of the SDL 2 library for the Nim language.
Stars: ✭ 108 (-6.09%)
Mutual labels:  wrapper

Airtable PHP client

A PHP client for the Airtable API. Comments, requests or bug reports are appreciated.

View examples

Get started

Please note that Airtable doesn't allow schema manipulation using their public API, you have to create your tables using their interface.

Once you created your base in the Airtable Interface open the API Docs to get your Base ID.

API Doc Airtable

The Base ID is a code that starts with 'app' followed by a mix of letter or numbers (appsvqGDFCwLC3I10).


Installation

If you're using Composer, you can run the following command:

composer require sleiman/airtable-php

You can also download them directly and extract them to your web directory.

Add the wrapper to your project

If you're using Composer, run the autoloader

require 'vendor/autoload.php';

Or include the Airtable.php file

include('../src/Airtable.php');
include('../src/Request.php');
include('../src/Response.php');

Initialize the class

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

Get all entries in table

We are getting all the entries from the table "Contacts".

$request = $airtable->getContent( 'Contacts' );

do {
    $response = $request->getResponse();
    var_dump( $response[ 'records' ] );
}
while( $request = $response->next() );

print_r($request);

Use params to filter, sort, etc

// 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 new entry

We will create new entry in the table Contacts

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

Batch Create now available, documentation available below

Update Contact

Use the entry ID to update the entry

$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

Expended Relationships (eager loading)

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.

When you don't pass an associative array, we assume that the field and the table name are the same.

$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.

$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.

$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.

Delete entry

Use the entry ID to delete the entry

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

Batch Delete now available, documentation available below

Quick Check (new)

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".

$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
}

Batch Create, Update, Delete

Airtable API now allows to create, update, and delete 10 records per API request.

Create

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

Update

$update = [];

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

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

Delete

$delete = [];

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

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

Credits

Copyright (c) 2019 - Programmed by Sleiman Tanios & Guillaume Laliberté

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].