PHP code example of omlet / smartcoop-sdk

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

    

omlet / smartcoop-sdk example snippets




$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$token = $_ENV['API_TOKEN'];
if (!$token) {
    throw new Exception('token environment variable is not set.');
}

$omlet = \Omlet\SmartCoop\Omlet::create($token);

$devices = $omlet->getDevices();
foreach ($devices as $device) {
    // a list of your devices
}

// a single device
$device = $omlet->getDeviceById('123456');

$group = $omlet->createGroup("New Group name");

$groups = $omlet->getGroups();
foreach ($groups as $$group) {
    // a list of your groups
}

// a single group
$group = $omlet->getGroupById('groupID')

$user = $omlet->getUser();

$deviceHandler = $omlet->getDeviceById('123456');
$deviceHandler->getActions();

$deviceHandler->action($action)

$configuration = $deviceHandler->getData()->getConfiguration()->copy();

$configuration = $deviceHandler->getData()->getConfiguration()->copy();
$doorConfiguration = $configuration->getDoor();
$doorConfiguration->setOpenTime("07:30");
$configuration->setDoor($doorConfiguration);

$device->updateConfiguration($configuration);

$groupHandler->updateGroupName("New Name");

$groupHandler->deleteGroup();

// invite a user with User access
$groupHandler->inviteUser("[email protected]", Acccess::USER);

// invite a user with Admin access
$groupHandler->inviteUser("[email protected]", Acccess::ADMIN);

$groupHandler->removeUser("[email protected]");

$groupHandler->updateUserAccess("[email protected]", Acccess::ADMIN);

$invites = $userHandler->getData()->getInvites();

// invites is an array containing GroupSubset objects. Pass one of these
// to acceptInvite

$userHandler->acceptInvite($groupSubset);

$invites = $userHandler->getData()->getInvites();

// invites is an array containing GroupSubset objects. Pass one of these
// to rejectInvite

$userHandler->rejectInvite($groupSubset);