airtable-php
airtable-php copied to clipboard
Get a NULL when trying to show some data
I'm getting this error when trying to get the data from my table, here is the code that im using.
Am I doing something wrong ?
Hi, can you post a picture of your table names? Airtable is very sensitive to table and column names.
those are the 2 tables that I'm trying to use
@cesantibanez were you able to fix the issue? The table names are fine. It looks like the client is not loading. If you can't make it work, I'm available today to help you. Let me know.
I am having this issue as well.
This returns NULL:
$airtable = new Airtable(array(
'api_key' => 'keyasdf',
'base' => 'appasdf'
));
$request = $airtable->getContent( 'Open' );
do {
$response = $request->getResponse();
var_dump( $response[ 'records' ] );
}
while( $request = $response->next() );
print_r($request);
This ended up being an issue with my local dev environment curl settings. I suspect this is the same issue @cesantibanez is having.
This fixed it for me: https://stackoverflow.com/a/31830614
Thanks for sharing what fixed it for you @cy-josh !
@cesantibanez , were you able to fix it?
I'm getting the same: NULL
What's wrong?
<?php
// if not using composer, uncomment this
include('airtable-php-2.2.9/src/Airtable.php');
include('airtable-php-2.2.9/src/Request.php');
include('airtable-php-2.2.9/src/Response.php');
use TANIOS\Airtable\Airtable;
$airtable = new Airtable(array(
'api_key' => 'pat3xxxxxxxxxxxxxx',
'base' => 'appHpxxxxxxxxxxxxxx',
));
$request = $airtable->getContent('Corporate CMS');
do {
$response = $request->getResponse();
var_dump($response['records']);
} while ($request = $response->next());
?>
I'm running my project with the PHP Built-in server: php -S project.test:4000
I tried what @cy-josh linked above but didn't work. Please share exactly how you solved. Thanks
@dangelion - 👋 Airtable deprecated the API keys for authentication. They moved to a personal token system https://airtable.com/developers/web/guides/personal-access-tokens
This is how I've been accessing results ...
$ch = curl_init([url]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.[access_token]
));
$result = curl_exec($ch);
If you need help designing a URL to submit this is a good resource - https://codepen.io/airtable/full/MeXqOg
Hi @leepettijohn thanks for answer! I never did it like that. So in you way you're not using the library of this Github? Could you post a real world code example? There's Airtable documentation about that way?
Let me know if this helps.
<?php
/*
// to see an example of how a URL should look when all the parameters are used - Airtable API encoder - https://codepen.io/airtable/full/MeXqOg
// REQUIRED
// Find Access Tokens here - https://airtable.com/create/tokens
// Find base here - https://airtable.com/api
$acctoken = '___';
$baseid = '___';
// I believe I used this template - https://www.airtable.com/universe/expn38xdYZDKzzTqX/the-best-furniture-planner
$tablename = 'Furniture';
$tableview = 'All furniture';
//Get results from AT
$url = 'https://api.airtable.com/v0/'.$baseid.'/'.$tablename.'?view='.$tableview;
$ch = curl_init(encodeUrl($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$acctoken
));
$result = curl_exec($ch);
print_r($result);
?>