Support

Documentation

The API client library

Writing an integration with a third party API is painful and invariably complicated. You have to understand the mindset and goals of the person designing the API, figure out its quirks, and write code which not only integrates with the API, but also does error handling and whatnot.

We strongly believe in Free and Open Source Software both for its technical superiority, and for its educational value. Therefore, if you are building a PHP-based Free and Open Source Software solution which needs to integrate with Akeeba Backup and Akeeba Solo we strongly encourage you to use our akeeba/json-backup-api client library package through Composer.

[Important]Important

The library package is licensed under the GNU Affero General Public License, version 3 of the license or, at your option, any later version (GNU-AGPL-3+). The GNU-AGPL-3+ license has a further restriction than the GNU General Public License (GNU-GPL-3+). If your software is accessible over a network, you must provide its source code to everyone who can access it over a network. If you are writing proprietary software, e.g. you are building a hosted service, and do not want this restriction we can sell you a proprietary license for the library. Pricing is determined according to the number of sites you expect to use this library with on a monthly basis, starting at €0.05 per site per month, with a minimum of 100 sites.

This library is the reference implementation of an Akeeba Backup JSON API client. This is what we use in Akeeba RemoteCLI (a CLI application to take backups remotely), Akeeba UNiTE (a CLI application to take backups remotely, and restore them unattended on a server), and Akeeba Panopticon (our self-hosted site monitoring software which can also take backups automatically).

To use this package, you will need two or three things in your composer.json file:

  • The akeeba/json-backup-api package itself.

  • A compatible HTTP request library. The library supports Guzzle, the Joomla Framework HTTP package, as well as any library which implements PSR-17 and PSR-18 such as PHP-HTTP, HTTPlug, and so on.

  • Optionally, composer/ca-bundle unless you can provide your own TLS Certification Authority cache

Assuming that you use Guzzle and composer/ca-bundle you can create a high level Akeeba Backup API client in a few lines of code:

// Create an Options object which tells the library where and
// how to connect to the backup software
$options = new \Akeeba\BackupJsonApi\Options([
    'capath' => \Composer\CaBundle\CaBundle::getBundledCaBundlePath(),
    'ua'     => 'MyFancyApp/1.2.3',
    'host'   => 'example.com',
    'secret' => 'Sυρ3rC4l1Fr@gil15ti(E><pial!d0ciou5',
]);
// Create an HTTP client object. Here, we are using one that
// makes use of Guzzle 7.
$httpClient = new \Akeeba\BackupJsonApi\HttpAbstraction\HttpClientGuzzle($options);
// Get the API client itself. 
$apiClient = new \Akeeba\BackupJsonApi\Connector($httpClient);

You can then use the high-level API client object to perform any operation supported. For example, taking a backup is a piece of cake:

$backupOptions = new \Akeeba\BackupJsonApi\DataShape\BackupOptions([
    'profile' => 5,
    'description' => 'Remote backup using the API client',
    'comment' => 'Look, mum! I can take backups without logging into the site!'
]);
$apiClient->backup($backupOptions, function ($data) {
    echo "Received backup tick\n";
    echo sprintf("Domain   : %s\n", $data->Domain);
    echo sprintf("Step     : %s\n", $data->Step);
    echo sprintf("Substep  : %s\n", $data->Substep);
    echo sprintf("Progress : %0.2f%%\n", $data->Progress);

    if (!empty($data->Warnings))
    {
        echo "Warnings\n========\n";

        foreach ($data->Warnings as $warning)
        {
            echo $warning . "\n";
        }
    }

    if (!$data->HasRun && empty($data->Error))
    {
        echo "The backup finished successfully.\n";
    }
    elseif (!empty($data->Error))
    {
        echo "The backup finished with an error:\n{$data->Error}\n";
    }
});

For all available high-level API calls look at https://github.com/akeeba/json-backup-api/tree/main/src/HighLevel. The method call is the same as the name of the invokable class in that folder. The parameters of each method are those of the magic __invoke method of the class. For example, to get the information of the backup software you can just do:

$info = $apiClient->information();

The available methods are also present as phpDocumentor @method tags in the \Akeeba\BackupJsonApi\Connector class. Most IDEs such as phpStorm, Visual Studio Code etc use this information to provide code auto-completion for the high level API object (the $apiClient in our example). This will greatly help you use the library.

The data returned by each high-level API object method is what is documented for the corresponding JSON API method. If you don't know which JSON API method corresponds to each method, look for the doQuery() calls in the same-named class under the \Akeeba\BackupJsonApi\HighLevel namespace. The first argument to the doQuery() method is the Akeeba Backup JSON API method.