1. Go to this page and download the library: Download geotab/mygeotab-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
geotab / mygeotab-php example snippets
// Store credentials in environment variables, not in source code
$api = new Geotab\API(
getenv('MYGEOTAB_USERNAME'),
getenv('MYGEOTAB_PASSWORD'),
getenv('MYGEOTAB_DATABASE')
);
$api->authenticate();
$results = $api->get("Device", ["resultsLimit" => 1]);
use Geotab\MyGeotabException;
try {
$toDate = new DateTime();
$fromDate = new DateTime();
$fromDate->modify("-1 month");
$violations = $api->get("DutyStatusViolation", [
"search" => [
"userSearch" => ["id" => "b1"],
"toDate" => $toDate->format("c"),
"fromDate" => $fromDate->format("c"),
],
"resultsLimit" => 10,
]);
echo "The driver has " . count($violations) . " violations!";
} catch (MyGeotabException $e) {
// Handle API error
}
$api->get(
"Device",
["resultsLimit" => 1],
function ($results) { var_dump($results); },
function ($error) { var_dump($error); }
);
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('mygeotab');
$logger->pushHandler(new StreamHandler('mygeotab.log'));
$stack = HandlerStack::create();
$stack->push(Middleware::log($logger, new MessageFormatter('{method} {uri} → {code}')));
$api = new Geotab\API(
getenv('MYGEOTAB_USERNAME'),
getenv('MYGEOTAB_PASSWORD'),
getenv('MYGEOTAB_DATABASE'),
'my.geotab.com',
new Client(['handler' => $stack])
);
$api->authenticate();