Code Monkey home page Code Monkey logo

airtable-php's People

Contributors

glaliberte avatar sleiman avatar torrancemiller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

airtable-php's Issues

Problems with accents

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.

Retrieve a record by ID (faster than quickCheck)

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.

Check if Airtable is down

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 new record id to an existing field using your library

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.

updateContent one entry doesn't work :'(

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? 😥

Pound sign(£) removed from field name

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 to get specific fields only using formula?

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!

504 Gateway Timeout for large airtable

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?

Early heads up: switching away from user API keys

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:

  • If you currently validate tokens (e.g. with a regex like /^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}$/)
    • For airtable-php: From a quick scan, it looks like you are treating keys as an opaque string. This is perfect, so please keep doing that 😄
  • Update documentation mentions of “API key” to the more general “API key or access token”

How to add Files, Images in attachment field?

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,

Accelerated need to limit large url requests to “list records”, with alternative POST version

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.

  • Q: What endpoints does this affect?
    • The 16k character limit applies to all current and future API request URLs
    • Based on our internal audit of current usage, this primarily impacts the “list records” endpoint, which is a GET request to /v0/{baseId}/{tableIdOrName} (https://airtable.com/developers/web/api/list-records)
  • Q: What is the impact of this change?
    • The vast majority of our API requests have remained well under the 16k character limit, and would not be affected
    • However, requests exceeding this limit will now be rejected, so we expect some calls to now require an update to handle the large cases. For example, requests whose query parameter for filterbyFormula is long enough to make the overall URL length to exceed that character limit
    • Therefore, we recommend either switching entirely to the alternative detailed below, or switching to it when you can detect that a request URL will exceed the 16k character limit
  • Q: What is the alternative?
  • Q: Why the urgency for this change?
    • I apologize for the inconvenience due to the accelerated timeline here. While we originally planned to start this enforcement in January 2023, we needed to deploy this change recently this week, as part of required infrastructure improvements to maintain the stability of our public API

Hey, there is a critical error.

I 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);
}
}

image

Comment on Token

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?

Getting error

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

Update multiple entries

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++;
};

Insert into a 'link to another record' field

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!

Get data from row past 100

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.

Date field error!

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

ErrorException: count() - quickCheck method

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 )

Getting all rows where checkbox is not checked

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

What does this error mean?

[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?

Ability to enable typecast

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

	}

Sort an expended response

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

Keep manual reorder on fields links

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 :/

Doesn't like tables with spaces

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.

Not all records returned

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!

Sort?

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

Easily Retrieve Once Specific Record

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?

Improvement: Adding Delete to the documentation

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.

How to add multiple conditions

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.

PHP 8.1 compatibility (ReturnTypeWillChange)

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

Reading data from a single record

The following is giving me a NULL response. It appears that parsedContent is a private method.

var_dump($db->getContent('TableName/{RecordID}')->getResponse()->parsedContent)

Issues with spaces in table names

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.

getting data from a table with "/" character in name

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.

syntax for use

There are some inconsistencies in the syntax between the samples and the downloads. I am attempting this code
Screen Shot 2020-08-19 at 1 13 37 PM

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.

Add some degree of error handling

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.