accessgrid/accessgrid-php

Official PHP SDK for AccessGrid API

Maintainers

Package info

github.com/Access-Grid/accessgrid-php

Homepage

pkg:composer/accessgrid/accessgrid-php

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-04-16 05:43 UTC

README

Official PHP SDK for the AccessGrid API.

Installation

Install via Composer:

composer require accessgrid/accessgrid-php

Requirements

  • PHP 7.4 or higher
  • cURL extension
  • JSON extension
  • Hash extension

Quick Start

Initializing the Client

<?php

require 'vendor/autoload.php';

use AccessGrid\Client;

$accountId = $_ENV['ACCOUNT_ID'];
$secretKey = $_ENV['SECRET_KEY'];

$client = new Client($accountId, $secretKey);

Issuing an Access Card

$card = $client->accessCards->provision([
    'card_template_id' => '0xd3adb00b5',
    'employee_id' => '123456789',
    'tag_id' => 'DDEADB33FB00B5',
    'full_name' => 'Employee name',
    'email' => 'employee@yourwebsite.com',
    'phone_number' => '+19547212241',
    'classification' => 'full_time',
    'department' => 'Engineering',
    'location' => 'San Francisco',
    'site_name' => 'HQ Building A',
    'workstation' => '4F-207',
    'mail_stop' => 'MS-401',
    'company_address' => '123 Main St, San Francisco, CA 94105',
    'start_date' => (new DateTime('now', new DateTimeZone('UTC')))->format('c'),
    'expiration_date' => '2026-04-01T00:00:00.000Z',
    'employee_photo' => '[image_in_base64_encoded_format]',
    'title' => 'Engineering Manager',
    'metadata' => [
        'department' => 'engineering',
        'badge_type' => 'contractor'
    ]
]);

echo "Install URL: {$card->url}\n";

Getting an Access Card

$card = $client->accessCards->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";

Updating an Access Card

$card = $client->accessCards->update([
   'card_id' => '0xc4rd1d',
   'employee_id' => '987654321',
   'full_name' => 'Updated Employee Name',
   'classification' => 'contractor',
   'department' => 'Marketing',
   'location' => 'New York',
   'site_name' => 'NYC Office',
   'workstation' => '2F-105',
   'mail_stop' => 'MS-200',
   'company_address' => '456 Broadway, New York, NY 10013',
   'expiration_date' => (new DateTime('now', new DateTimeZone('UTC')))->modify('+3 months')->format('c'),
   'employee_photo' => '[image_in_base64_encoded_format]',
   'title' => 'Senior Developer'
]);

echo "Card updated successfully\n";

Listing Access Cards

$cards = $client->accessCards->list('0xd3adb00b5');
foreach ($cards as $card) {
    echo $card . "\n";
}

// With state filter
$activeCards = $client->accessCards->list('0xd3adb00b5', 'active');

Managing Card States

// Suspend a card
$client->accessCards->suspend(['card_id' => '0xc4rd1d']);

// Resume a card
$client->accessCards->resume(['card_id' => '0xc4rd1d']);

// Unlink a card
$client->accessCards->unlink(['card_id' => '0xc4rd1d']);

// Delete a card
$client->accessCards->delete(['card_id' => '0xc4rd1d']);

Console (Enterprise Features)

Creating a Card Template

$template = $client->console->createTemplate([
   'name' => 'Employee Access Pass',
   'platform' => 'apple',
   'use_case' => 'employee_badge',
   'protocol' => 'desfire',
   'allow_on_multiple_devices' => true,
   'watch_count' => 2,
   'iphone_count' => 3,
   'background_color' => '#FFFFFF',
   'label_color' => '#000000',
   'label_secondary_color' => '#333333',
   'support_url' => 'https://help.yourcompany.com',
   'support_phone_number' => '+1-555-123-4567',
   'support_email' => 'support@yourcompany.com',
   'privacy_policy_url' => 'https://yourcompany.com/privacy',
   'terms_and_conditions_url' => 'https://yourcompany.com/terms',
   'metadata' => [
       'version' => '2.1',
       'approval_status' => 'approved'
   ]
]);

echo "Template created successfully: {$template->id}\n";

Updating a Card Template

$template = $client->console->updateTemplate([
   'card_template_id' => '0xd3adb00b5',
   'name' => 'Updated Employee Access Pass',
   'allow_on_multiple_devices' => true,
   'watch_count' => 2,
   'iphone_count' => 3,
   'background_color' => '#FFFFFF',
   'label_color' => '#000000',
   'label_secondary_color' => '#333333',
   'support_url' => 'https://help.yourcompany.com',
   'support_phone_number' => '+1-555-123-4567',
   'support_email' => 'support@yourcompany.com',
   'privacy_policy_url' => 'https://yourcompany.com/privacy',
   'terms_and_conditions_url' => 'https://yourcompany.com/terms',
   'metadata' => [
       'version' => '2.2',
       'last_updated_by' => 'admin'
   ]
]);

echo "Template updated successfully: {$template->id}\n";

Reading a Card Template

$template = $client->console->readTemplate([
   'card_template_id' => '0xd3adb00b5'
]);

echo "Template ID: {$template->id}\n";
echo "Name: {$template->name}\n";
echo "Platform: {$template->platform}\n";
echo "Protocol: {$template->protocol}\n";
echo "Multi-device: {$template->allow_on_multiple_devices}\n";

Event Logs

$events = $client->console->eventLog([
   'card_template_id' => '0xd3adb00b5',
   'filters' => [
       'device' => 'mobile',
       'start_date' => (new DateTime('30 days ago'))->format('c'),
       'end_date' => (new DateTime('now'))->format('c'),
       'event_type' => 'install'
   ]
]);

foreach ($events as $event) {
   echo "Event: {$event->type} at {$event->timestamp} by {$event->user_id}\n";
}

Ledger Items

$result = $client->console->ledgerItems([
    'page' => 1,
    'per_page' => 50,
    'start_date' => (new DateTime('30 days ago'))->format('c'),
    'end_date' => (new DateTime('now'))->format('c')
]);

foreach ($result['ledger_items'] as $item) {
    echo "Amount: {$item['amount']}, Kind: {$item['kind']}, Date: {$item['created_at']}\n";
}

iOS In-App Provisioning Preflight

$response = $client->console->iosPreflight([
    'card_template_id' => '0xt3mp14t3-3x1d',
    'access_pass_ex_id' => '0xp455-3x1d'
]);

echo "Provisioning Credential ID: " . $response->provisioningCredentialIdentifier . "\n";
echo "Sharing Instance ID: " . $response->sharingInstanceIdentifier . "\n";
echo "Card Template ID: " . $response->cardTemplateIdentifier . "\n";
echo "Environment ID: " . $response->environmentIdentifier . "\n";

Pass Template Pairs

$result = $client->console->listPassTemplatePairs([
   'page' => 1,
   'per_page' => 50
]);

foreach ($result['pass_template_pairs'] as $pair) {
   echo "Pair: {$pair->name} (ID: {$pair->id})\n";
   if ($pair->androidTemplate) {
       echo "  Android: {$pair->androidTemplate->name}\n";
   }
   if ($pair->iosTemplate) {
       echo "  iOS: {$pair->iosTemplate->name}\n";
   }
}

HID Organizations

// Create HID org
$org = $client->console->hid->orgs->create([
    'name' => 'My Org',
    'full_address' => '1 Main St, NY NY',
    'phone' => '+1-555-0000',
    'first_name' => 'Ada',
    'last_name' => 'Lovelace'
]);

// List all HID orgs
$orgs = $client->console->hid->orgs->list();

// Complete HID org registration
$result = $client->console->hid->orgs->activate([
    'email' => 'admin@example.com',
    'password' => 'hid-password-123'
]);

Landing Pages

// List all landing pages
$landingPages = $client->console->listLandingPages();

foreach ($landingPages as $page) {
    echo "ID: {$page->id}, Name: {$page->name}, Kind: {$page->kind}\n";
    echo "  Password Protected: {$page->password_protected}\n";
    if ($page->logo_url) {
        echo "  Logo URL: {$page->logo_url}\n";
    }
}

// Create a landing page
$landingPage = $client->console->createLandingPage([
    'name' => 'Miami Office Access Pass',
    'kind' => 'universal',
    'additional_text' => 'Welcome to the Miami Office',
    'bg_color' => '#f1f5f9',
    'allow_immediate_download' => true
]);

echo "Landing page created: {$landingPage->id}\n";
echo "Name: {$landingPage->name}, Kind: {$landingPage->kind}\n";

// Update a landing page
$landingPage = $client->console->updateLandingPage('0xlandingpage1d', [
    'name' => 'Updated Miami Office Access Pass',
    'additional_text' => 'Welcome! Tap below to get your access pass.',
    'bg_color' => '#e2e8f0'
]);

echo "Landing page updated: {$landingPage->id}\n";
echo "Name: {$landingPage->name}\n";

Credential Profiles

// List all credential profiles
$profiles = $client->console->credentialProfiles->list();

foreach ($profiles as $profile) {
    echo "ID: {$profile->id}, Name: {$profile->name}, AID: {$profile->aid}\n";
}

// Create a credential profile
$profile = $client->console->credentialProfiles->create([
    'name' => 'Main Office Profile',
    'app_name' => 'KEY-ID-main',
    'keys' => [
        ['value' => 'your_32_char_hex_master_key_here'],
        ['value' => 'your_32_char_hex__read_key__here']
    ]
]);

echo "Profile created: {$profile->id}\n";
echo "AID: {$profile->aid}\n";

Error Handling

try {
    $card = $client->accessCards->provision($data);
} catch (AccessGrid\Exceptions\AuthenticationException $e) {
    echo "Authentication failed: " . $e->getMessage();
} catch (AccessGrid\Exceptions\AccessGridException $e) {
    echo "API error: " . $e->getMessage();
}

License

MIT License

Feature Matrix

Endpoint Method Supported
POST /v1/key-cards accessCards->provision() Y
GET /v1/key-cards/{id} accessCards->get() Y
PATCH /v1/key-cards/{id} accessCards->update() Y
GET /v1/key-cards accessCards->list() Y
POST /v1/key-cards/{id}/suspend accessCards->suspend() Y
POST /v1/key-cards/{id}/resume accessCards->resume() Y
POST /v1/key-cards/{id}/unlink accessCards->unlink() Y
POST /v1/key-cards/{id}/delete accessCards->delete() Y
POST /v1/console/card-templates console->createTemplate() Y
PUT /v1/console/card-templates/{id} console->updateTemplate() Y
GET /v1/console/card-templates/{id} console->readTemplate() Y
GET /v1/console/card-templates/{id}/logs console->eventLog() Y
GET /v1/console/card-template-pairs console->listPassTemplatePairs() Y
POST /v1/console/card-template-pairs console->createPassTemplatePair() Y
POST /v1/console/card-templates/{id}/ios_preflight console->iosPreflight() Y
GET /v1/console/ledger-items console->ledgerItems() Y
GET /v1/console/landing-pages console->listLandingPages() Y
POST /v1/console/landing-pages console->createLandingPage() Y
PUT /v1/console/landing-pages/{id} console->updateLandingPage() Y
GET /v1/console/credential-profiles console->credentialProfiles->list() Y
POST /v1/console/credential-profiles console->credentialProfiles->create() Y
GET /v1/console/webhooks console->listWebhooks() Y
POST /v1/console/webhooks console->createWebhook() Y
DELETE /v1/console/webhooks/{id} console->deleteWebhook() Y
POST /v1/console/hid/orgs console->hid->orgs->create() Y
POST /v1/console/hid/orgs/activate console->hid->orgs->activate() Y
GET /v1/console/hid/orgs console->hid->orgs->list() Y