Skip to main content
Version: 4.9

PHP client

Installation

The PHP client is currently installed by retrieving an archive containing the client, available at the following URL: https://pkg.bluemind.net/pkg/<numéro technique de BM>/clients/

:::tip Technical version number

BlueMind's technical version number can be found on the BlueMind download page or in the section "About" of the user interface.

:::

Usage

Authentication

The client uses the BMClient class to start:

<?php
require 'BM/AuthenticationClient.php';
require 'BM/DomainsClient.php';

$url="https://external-url";
$token="admin";

$authClient = new BM\AuthenticationClient($url, NULL);
$loginResponse = $authClient->login('admin0@global.virt', $token, 'bm-php-client');
echo "Login result : ".$loginResponse->status;
?>
  • url : defines the access url to the BlueMind server.
  • token : corresponds to the password or token of admin0; in this example, we use the admin0 token to have extended rights to the API.
    It is also possible to authenticate as :
    <?php
    require 'BM/AuthenticationClient.php';
    require 'BM/DomainsClient.php';

    $url="https://external-url";
    $token="admin";

    $authClient = new BM\AuthenticationClient($url, NULL);
    $loginResponse = $authClient->login('admin0@global.virt', $token, 'bm-php-client');
    print "Login result : ".$loginResponse->status;
    $authClient = new BM\AuthenticationClient($url, $loginResponse->authKey);
    $token = $authClient->su("user@local.lan");
    print "sudo result : ".$token->status
    ?>

Note: It is also possible to use a user's API key instead of their password.

Listing domains

<?php
require 'BM/AuthenticationClient.php';
require 'BM/DomainsClient.php';

$url="https://external-url";
$token="admin";

$authClient = new BM\AuthenticationClient($url, NULL);
$loginResponse = $authClient->login('admin0@global.virt', $token, 'bm-php-client');
print "Login result : " + $loginResponse->status;

$domainClient = new BM\DomainsClient($url, $loginResponse->authKey);
$domains = $domainClient->all();
#var_dump($domains);
foreach ($domains as $domain)
{
print $domain->value->name."\n";
}
?>

Listing events

<?php
require 'BM/AuthenticationClient.php';
require 'BM/DomainsClient.php';
require 'BM/UserClient.php';
require 'BM/CalendarClient.php';
require 'BM/ContainersClient.php';
require 'BM/ContainerQuery.php';

// BEGIN CONF
$url="https://external-url";
$token="admin";
$user="user@local.lan";
$domain="local.lan";
// END CONF

$authClient = new BM\AuthenticationClient($url, NULL);
$loginResponse = $authClient->login('admin0@global.virt', $token, 'bm-php-client');
//var_dump($loginResponse);
print "Login result : " + $loginResponse->status;

$userClient = New BM\UserClient($url, $loginResponse->authKey, $domain);
$userValue = $userClient->byEmail($user);

$containersClient = New BM\ContainersClient($url, $loginResponse->authKey);
$query = New BM\ContainerQuery();
$query->owner = $userValue->uid;
$query->type = "calendar";
$containers = $containersClient->allForUser($domain, $userValue->uid, $query);

foreach ($containers as $container)
{
print "calendar : ".$container->name. " uid : ".$container->uid."\n";
$calendarClient = New BM\CalendarClient($url, $loginResponse->authKey, $container->uid);
foreach ($calendarClient->list_()->values as $event)
{
print "Event : ".$event->value->main->summary."\n";
}
}
?>

Examples are available on our repository: https://forge.bluemind.net/stash/projects/BA/repos/bluemind-samples/browse/php-api-examples

FAQ

Certificate issues

If you are using an unknown certificate, you must change the value for CURLOPT_SSL_VERIFYPEER to FALSE in the file BM/GlobalEnv.php.