PHP code example of klevio / klevio-api

1. Go to this page and download the library: Download klevio/klevio-api 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/ */

    

klevio / klevio-api example snippets


use Klevio\KlevioApi\Facades\KlevioApi;

// Grant Access with Metadata
$response = KlevioApi::grantKey(
    propertyId: 'property-123',
    email: '[email protected]',
    from: '2024-01-01T00:00:00Z',
    to: '2024-01-07T23:59:59Z',
    metadata: [
        'reservationId' => 'booking-123',
        'guestName' => 'John Doe',
        'roomNumber' => '101'
    ]
);

// List Property Keys
$keys = KlevioApi::getKeys('property-123');

// Control Lock
$response = KlevioApi::useKey('key-123');

use GuzzleHttp\Exception\RequestException;

try {
    $response = KlevioApi::useKey('key-123');
} catch (RequestException $e) {
    Log::error('Klevio API Error', [
        'message' => $e->getMessage(),
        'code' => $e->getCode()
    ]);
}