Basic PHP usage

Hi, I’m a first time user.
I have created my sandbox applicating using a specific email address and I have both an API KEY and a GRANT ID.
The HTML header is filled with:
$headr = 'Authorization: Bearer ’ . $_ENV[‘ACCESS_TOKEN’];
I have tried placing both the API KEY and the GRANT ID in the .env file, I have made sure its correclty read, but I have no response from either the ReadInbox.php or the SendEmail.php apps. Anyone got it to work and can help understand what should go into the header ?
thank you in advance,
Pedro

I traced the error to:
Curl Error: SSL certificate problem: unable to get local issuer certificate, using URL https://api.nylas.com/messages?in=inbox&unread=true&limit=1

Hello @pcasqueiro :wave: I assume you’re using V3 but with a V2 example :thinking: My fault :disappointed: as I haven’t updated the PHP examples…I will do that today :smile:

Anyways…here’s how you should do it to read emails :wink:

<?php
# Import your dependencies
require_once('vendor/autoload.php');

# Load env variables
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$headr = array();
$headr[] = 'Accept: application/json';
$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: Bearer ' . $_ENV['NYLAS_API_KEY'];

$url = "https://api.us.nylas.com/v3/grants/" . $_ENV['GRANT_ID'] . "/messages?limit=10";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = json_decode(curl_exec($ch));
curl_close($ch);

#echo $result->data;

foreach ($result->data as $msg) {
  #echo $msg->from[0]->email;
  echo $msg->id . "&emsp;";
  echo $msg->date . "&emsp;";
  echo $msg->subject . "&emsp;";
  echo $msg->from[0]->email;
  echo "<br><br>";
}

I installed composer require vlucas/phpdotenv first :slight_smile:

@pcasqueiro :man_shrugging:t2: I actually beat myself :joy: I actually updated the PHP repo some time ago but forget to update the main branch :sweat_smile:

Here it is :wink: