Official PHP SDK for the AccessGrid API.
Install via Composer:
composer require accessgrid/accessgrid-php- PHP 7.4 or higher
- cURL extension
- JSON extension
- Hash extension
<?php
require_once 'vendor/autoload.php';
use AccessGrid\AccessGridClient;
// Initialize the client
$client = new AccessGridClient('your-account-id', 'your-secret-key');
// Issue a new access card
$card = $client->getAccessCards()->issue([
'template_id' => 'your-template-id',
'full_name' => 'John Doe',
'expiration_date' => '2024-12-31'
]);
echo "Card issued: " . $card->id . "\n";
// Get a specific card
$card = $client->getAccessCards()->get('0xc4rd1d');
echo "Card ID: " . $card->id . "\n";
echo "State: " . $card->state . "\n";
echo "Full Name: " . $card->full_name . "\n";
echo "Install URL: " . $card->install_url . "\n";
echo "Expiration Date: " . $card->expiration_date . "\n";
echo "Card Number: " . $card->card_number . "\n";
echo "Site Code: " . $card->site_code . "\n";
echo "Devices: " . count($card->devices) . "\n";
echo "Metadata: " . json_encode($card->metadata) . "\n";
// List cards for a template
$cards = $client->getAccessCards()->list('your-template-id');
foreach ($cards as $card) {
echo $card . "\n";
}
// Suspend a card
$suspendedCard = $client->getAccessCards()->suspend($card->id);
echo "Card suspended: " . $suspendedCard->state . "\n";The main client class for interacting with the AccessGrid API.
new AccessGridClient(string $accountId, string $secretKey, string $baseUrl = 'https://api.accessgrid.com')Access the access cards service via $client->getAccessCards().
issue(array $data): AccessCard- Issue a new access cardprovision(array $data): AccessCard- Alias for issue()get(string $cardId): AccessCard- Get details about a specific access cardupdate(string $cardId, array $data): AccessCard- Update an existing cardlist(string $templateId, ?string $state = null): AccessCard[]- List cards for a templatesuspend(string $cardId): AccessCard- Suspend a cardresume(string $cardId): AccessCard- Resume a suspended cardunlink(string $cardId): AccessCard- Unlink a carddelete(string $cardId): AccessCard- Delete a card
Access the console service via $client->getConsole().
createTemplate(array $data): Template- Create a new card templateupdateTemplate(string $templateId, array $data): Template- Update a templatereadTemplate(string $templateId): Template- Get template detailsgetLogs(string $templateId, array $params = []): array- Get event logs
The SDK throws the following exceptions:
AccessGrid\Exceptions\AccessGridException- Base exception for all API errorsAccessGrid\Exceptions\AuthenticationException- Thrown for authentication failures
try {
$card = $client->getAccessCards()->issue($data);
} catch (AccessGrid\Exceptions\AuthenticationException $e) {
echo "Authentication failed: " . $e->getMessage();
} catch (AccessGrid\Exceptions\AccessGridException $e) {
echo "API error: " . $e->getMessage();
}MIT License