airtable-php icon indicating copy to clipboard operation
airtable-php copied to clipboard

Get a NULL when trying to show some data

Open cesantibanez opened this issue 2 years ago • 5 comments

image

I'm getting this error when trying to get the data from my table, here is the code that im using. image

Am I doing something wrong ?

cesantibanez avatar Aug 02 '22 13:08 cesantibanez

Hi, can you post a picture of your table names? Airtable is very sensitive to table and column names.

sleiman avatar Aug 02 '22 13:08 sleiman

image

those are the 2 tables that I'm trying to use

cesantibanez avatar Aug 02 '22 13:08 cesantibanez

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

sleiman avatar Aug 03 '22 12:08 sleiman

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

cy-josh avatar Aug 12 '22 14:08 cy-josh

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

cy-josh avatar Aug 12 '22 16:08 cy-josh

Thanks for sharing what fixed it for you @cy-josh !

@cesantibanez , were you able to fix it?

glaliberte avatar Nov 01 '22 13:11 glaliberte

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 avatar Feb 29 '24 09:02 dangelion

@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

leepettijohn avatar Feb 29 '24 13:02 leepettijohn

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?

dangelion avatar Feb 29 '24 15:02 dangelion

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

?>

leepettijohn avatar Feb 29 '24 18:02 leepettijohn