sleiman / airtable-php Goto Github PK
View Code? Open in Web Editor NEWA PHP client for the Airtable API
License: GNU General Public License v3.0
A PHP client for the Airtable API
License: GNU General Public License v3.0
Hi!
First of all: thanks for your project ;)
I have a problem when I use tab names with accents, example:
$params = [
'maxRecords' => 30,
'view' => 'myView'
];
$relations = [
'Métier' => rawurlencode('Types de métier'),
'Ecosystème' => 'Ecosystème'
];
$companiesAT = $airtable->getContent('myTable', $params, $relations)->getResponse();
As you can see I have to apply rawurlencode
on tab name to work ("Types de métier" works, "Ecosystème" doesn't work).
The field with accents work ("Métier" for example).
Maybe same problem with other elements like db name (I don't test them for now).
I think we have to proceed here:
if( ! $this->is_post || strtolower( $this->is_post ) === 'delete' )
{
if (!empty($this->data)) {
// rawurlencode or replace accents
$data = http_build_query($this->data);
$request .= "?" . $data;
}
$url_encoded = true;
}
in init()
function in Request.php
.
Hi there. First, thanks a lot for this wrapper. I use it in a couple of my projects.
I saw there is a quickCheck call, which would return one record if you filter right.
In my application, I also have the recIds of the Airtable records, so I wonder if there is a way to retrieve single record and if it is noticeably faster compared to quickCheck. To clarify, I mean this API URI:
https://api.airtable.com/v0/appE5iirABCD9emg7/MyTable/reclnxjiMeSl1234
I know that in most cases people don't use recIds, but something like the email address as their IDs, but in my case I want to make it more robust, so I ask my editors to copy&paste the recId of the record they want to show in our CMS, because Airtable is not very strict with the natural keys and allows duplicates and to change them.
Hi,
I just received an email from Airtable saying we are using a legacy API Key.
Do you plan to support the new authentication methods?
Here is the announcement: https://community.airtable.com/t5/announcements/new-api-capabilities-now-in-ga-and-upcoming-api-keys-deprecation/ba-p/141824
Regards.
Hi,
I love the wrapper, good job! Twice this week Airtable was down and both times it wrecked my system sitting on top of it.
Is there a way to validate if Airtable is up before I start pulling data from the API?
Thanks,
Ben
How to append a new record id to an existing field using airtable api in PHP. I have A and B table, so A table has F field that contain the records of B table, so now, I want to append new record ids to F field, but I am not sure how can I append new record ids to an existing F field using PHP and airtable api. Currently, I am using https://github.com/sleiman/airtable-php library. Please share your idea if you know something. Thanks in advance.
Hi!
I have a problem when I try to update one entry with updateContent(), I follow the doc:
$tableName = 'Companies';
$recordId = 'recFjrQs8zRZU80kN';
$lastSyncDate = date('Y-m-d H:i:s');
$values = [
'name' => 'Banana',
'last_sync_date' => $lastSyncDate,
];
$update = $airtable->updateContent("$tableName/$recordId", $values);
// $update = $airtable->updateContent($tableName . '/{' . $recordId . '}', $values); // Same error message
I have this error message:
"type":"TABLE_NOT_FOUND","message":"Could not find table Companies/recFjrQs8zRZU80kN in application app75638392XXXX"
The curl URL looks like that:
https://api.airtable.com/v0/app75638392XXXX/Companies%2FrecFjrQs8zRZU80kN
The Request\content_type value:
Companies/recFjrQs8zRZU80kN
But when I use bulk update it works:
$tableName = 'Companies';
$recordId = 'recFjrQs8zRZU80kN';
$lastSyncDate = date('Y-m-d H:i:s');
$values = [];
$values[] = [
'id' => $recordId,
'fields' => [
'name' => 'Banana',
'last_sync_date' => $lastSyncDate,
]
];
$update = $airtable->updateContent($tableName, $values);
Can you help me please? 😥
For a field name with Pound Sign(£), the response is returning a field name with no pound sign. My request data is:
$data = array( "Total Value - £" => 200 );
For which I get an error message:
"Unknown field name: "Total Value - ""
How are you?
I love to use your library.
I use the getContent and getResponse functions to get fields.
Normally, airtable returns all fields from a table, but I don't want to get all fields because I don't need all fields and if I get all fields, there might be a speed problem.
I hope you understand what I said.
Please let me know, thank you!
I have an airtable with 2000+ records. I'm trying to fetch all the records and insert them into mysql. I keep getting a 504 Gateway timeout after a certain amount of time. The records still get inserted - but is there a way to prevent that error?
Hi! I’m Fred, an engineer on the Airtable API team. I’m writing here to share some plans we have to move away from user API keys, with a goal of communicating it early so you have time to triage and prioritize work needed.
First, some context. We recently published a new developer doc site, and announced two new authentication methods, as well as new endpoints and capabilities those methods support: https://airtable.com/developers/web/api/changelog#anchor-2022-11-15
Since these new authentication methods (personal access tokens and OAuth integration access tokens) are much more secure than the current user API key authentication method, we are limiting the new endpoints and capabilities to only be available to the new methods.
The medium term plan is to deprecate user API keys. We are still working on the exact details, but the deprecation period will last 1 year, and we expect it to begin at the start of next year (Jan 2023).
Based on this we recommend preparing to support the new API token format:
/^key[a-zA-Z0-9]{14}$/
), start supporting the new personal access token key format as well (/^pat[a-zA-Z0-9]{14}\.[0-9a-f]{64}$/
)
First of all, amazing work and thanks a lot..
My question is How to add images, PDFs etc in attachment field ?
does this API got certain calls? can you point me to the right direction ?
Thanks,
Hi! Fred here again, from the Airtable API team. Another update is that as part of recent infrastructure improvements to airtable.com, we needed to accelerate enforcement of rejecting any requests whose request URLs exceed 16k characters. The changes described below are in effect today.
/v0/{baseId}/{tableIdOrName}
(https://airtable.com/developers/web/api/list-records)filterbyFormula
is long enough to make the overall URL length to exceed that character limit/v0/{baseId}/{tableIdOrName}/listRecords
, and encode the query params as the body of that POST request. We currently still require two parameters to remain as query params, timeZone
and userLocale
; you can see the full details and examples here: https://support.airtable.com/docs/enforcement-of-url-length-limit-for-web-api-requestsI tried to use this function because I have 2 tables and they're linked each other with columns.
But this functions are not working. Could you please guide me or fix this issue?
Here is my code snippet.
if ( isset($record->fields->Deals) ) {
$deals = $record->fields->Deals;
$cnt = count($record->fields->Deals);
for ( $i = 0; $i < $cnt; $i++ ) {
echo AIRTABLE_TABLE."/".$deals[$i];
$expended = $airtable->getContent( AIRTABLE_TABLE."/".$deals[$i], false, [
'Deal ID' => 'deals'
]);
print_r($expended);
}
}
From visiting the Developer section in AirTable I have noticed they are stating that API keys will no longer be used in the future and they are switching to Tokens - are you able to provide any input on the compatibility of airtable-php with this new Token architecture?
include('../src/Airtable.php');
include('../src/Request.php');
include('../src/Response.php');
use \TANIOS\Airtable\Airtable;
$airtable = new Airtable(array(
'api_key' => '',
'base' => '*'
));
$request = $airtable->getContent( 'User' );
do {
$response = $request->getResponse();
var_dump( $response[ 'records' ] );
}
while( $request = $response->next() );
print_r($request);
and getting content then got an error.
Fatal error: Uncaught Error: Class 'Stiphle\Throttle\LeakyBucket' not found in /var/www/html/myairtableproject/airtable-php-master/src/Airtable.php:46 Stack trace: #0 /var/www/html/myairtableproject/demo.php(28): TANIOS\Airtable\Airtable->__construct(Array) #1 {main} thrown in /var/www/html/myairtableproject/airtable-php-master/src/Airtable.php on line 46
Is there a suggested way to update multiple entries at once? I'm currently using a foreach loop and it seems to work, but I'm not sure if that's the best way and if I will run into the rate limit? Just passing the arrays doesn't seem to work.
$updateDetails = [ ... my data ... ];
$updateRecords = [ ... records i want to update ... ];
$i = 0;
foreach ($updateRecords as $updateRecord) {
$update = $airtable->updateContent($updateRecords[$i], $updateDetails[$i]);
$i++;
};
Hello! First, thank you very much for the library!
Does anyone know how to insert a value into a 'link to another record' field? When I try to enter by name, it complains that it is duplicated and the key cannot be duplicated (which makes sense).
Any tips will be appreciated! thanks again!
Hi sleiman...
If I have a table that has 125 records how would I get the data from record 101 for example?
I see there is two records arrays but not sure how to access that second offset array to get my data.
Thanks in advance for the help.
I have date field on airtable. But when I try to add date to this field using your library, it does not work. Not inserted. Can you let me know how can I add it? Thanks
We depend on this package, please update!
I get the above error after initializing the class.
ErrorException: count(): Parameter must be an array or an object that implements Countable in ~/vendor/sleiman/airtable-php/src/Airtable.php:136
$check = $airtable->quickCheck("Table", "QR Code", $profile->qr_code);
if( $check->count > 0 )
How would I go about getting all rows where a checkbox is false? I have tried the following with no success.
$params = array(
"filterByFormula" => "AND ( Task_Written == FALSE )"
);
$request_items = $airtable->getContent( 'Invoice Items', $params );
$response_items = $request_items->getResponse();
[2022-12-01 11:28:32] production.ERROR: Undefined array key "base" {"exception":"[object] (ErrorException(code: 0): Undefined array key "base" at /home/forge/dev1.rrdevours.monster/vendor/sleiman/airtable-php/src/Airtable.php:42)
[stacktrace]
I'm guessing it's just pssing through wrong data or something?
I need use more than 100 data of a table in Airtable,
I saw that we need use pageSize, and after offset to this, but i don't know how make this in airtable-php api
Thanks!
Would be good to be able to enable type casting when creating entries
function saveContent($content_type,$fields,$typecast = false)
{
if( ! $this->_detectBatch( $fields ) )
{
$fields = array('fields' => $fields);
}
else
{
$fields = array('records' => $fields);
}
if($typecast) {
$fields['typecast'] = true;
}
$request = new Request( $this, $content_type, $fields, true );
return $request->getResponse();
}
When I am doing an expended request where can I pass in my sort parameter?
$params = array(
'sort'=> array(
array( 'field' => 'Job_Name', 'direction' => 'asc')
)
);
$expended = $airtable->getContent( "Customers/recpJGOaJYB4G36PU", $params, false, [
'Customer Details'
] );
Hi,
Can you give example to just fetch one row or specify the number of rows. Also, how to pass view as a parameter similar to airtable API.
Hello, it's me (again :) ).
I have a new problem:
My records have several fields with type "Link to another record", and I would like keep the manual reorder when I retrieve them, but this isn't the case today :'(
The manual reorder explanation: https://support.airtable.com/hc/en-us/articles/217521267
I started to research where the problem comes from and I viewed that related_field
are retrieved by a new API call with a filterByFormula
on RECORD_ID()
in OR, example:
OR(RECORD_ID() = 'recdpDDhXpoZOhvny', RECORD_ID() = 'recNwuDQa3evOLZnm')
The full API call:
https://api.airtable.com/v0/app75XXX/Team%20Members?filterByFormula=OR%28RECORD_ID%28%29+%3D+%27recdpDDhXpoZOhvny%27%2C+RECORD_ID%28%29+%3D+%27recNwuDQa3evOLZnm%27%29
So the sort order is lost here, because the API return records without considering the sort order in parent table :/
Thanks for these wrapper classes.
I was struggling to get even the most straightforward 'retrieve all records in a table' working, until I did rawURLEncode on the $request
string:
$curl = curl_init($this->airtable->getApiUrl(rawurlencode($request)));
My table name has spaces (and a colon) in it, passing it raw was returning am empty response.
Please provide input on why the following code:
$records = $airtable->getContent( 'Contact');
return $records->getResponse();
Would not return all the records in the Contact table and some possible reason for this issue. Thank you!
Hi! Is there a way to create a column if its not available on the table?
How can I specify a sort order? I tried this but had no luck -
$params = array(
'sort'=> array('field' => 'Brand', 'direction' => 'desc'),
);
$request = $airtable->getContent($air_sheet, $params);
What is the easiest way to retrieve a specific record from another table without taxing the API? For example I have a product with a room associated to it. How would I retrieve the Name of the room from the Rooms table? Would it be using the expended relationships or can I filter a field by the unique record id?
Hello! this is simply a suggestion to improve. It took me a while to realize what the call was to do the delete. Finally I realized that it was similar to the update. I suggest adding it in the documentation for people who might need it and for some reason could not figure it out by reading the code.
I want to add multiple conditions in getContent. I tried like this but it is not working.
"filterByFormula" => "AND( Status = 'New' ) AND ( Color='Red')",
Please add some examples of multiple conditions with AND, OR operators.
How do you get field names with spaces? I keep getting errors.
Do you know if it is possible to write into the comments section of the activity area of airtable?
Getting this error when using PHP 8.1:
Return type of TANIOS\Airtable\Request::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in Request.php:148
The following is giving me a NULL
response. It appears that parsedContent
is a private method.
var_dump($db->getContent('TableName/{RecordID}')->getResponse()->parsedContent)
any idea how to search with multiple columns? unlike just single column lookup in QuickCheck()
I had a rough time trying to debug this issue. Trying to add a new record to one of my tables, and this was producing a blank response. No error message, but the record was not getting created:
$airtable->saveContent('Table Name', $fields);
I finally figured out, after much trial and error, that the space in the table name needed to be url encoded.
So this works:
$airtable->saveContent('Table%20Name', $fields);
But it feels very hacky.
Overall nice and helped me to integrate into my app big issues is . Please set it to
Thanks
for example $request = $airtable->getContent('Institution/Location');
will return NOT_FOUND
error. a quick workaround for this is to just use the table ID instead, but wanted to flag here anyway in case someone else runs into same issue.
There are some inconsistencies in the syntax between the samples and the downloads. I am attempting this code
and the echo for "new array" is never executing leading me to believe there is an issue with the $airtable variable declaration.
the use command is sometimes shown as
use TANIOS\Airtable
and sometimes
use \TANIOS\Airtable
so I'm not sure if this could be related.
When cURL fails and returns null, the library just passes that on with no clean way to diagnose the issue. I found myself using a closure so I can access the private cURL handle and use curl_error()
to retrieve the actual error. If the library can provide a method to access the error or expose the cURL handle, that would be lovely.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.