sleiman/airtable-php
Composer 安装命令:
composer require sleiman/airtable-php
包简介
A PHP wrapper for the Airtable API
README 文档
README
A PHP client for the Airtable API. Comments, requests or bug reports are appreciated.
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.
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@domain.com', ); // 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","jon@wordlco.com"); 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é
sleiman/airtable-php 适用场景与选型建议
sleiman/airtable-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 802.97k 次下载、GitHub Stars 达 165, 最近一次更新时间为 2017 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sleiman/airtable-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sleiman/airtable-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 802.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 166
- 点击次数: 13
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-27
