Skip to Content
SDKsPHP

PHP SDK

A PHP client built on Guzzle. It requires PHP 8.1 or later.

composer require lman/sdk

Packagist  · GitHub  · API Reference 

How it works

The SDK has one class per section of the API Reference , like LicenseManager\Api\LicensesApi or LicenseManager\Api\CustomersApi, and one method per endpoint, named after it: Create a license is createLicense. Each method takes the path parameters and the body, then the optional parameters, best passed by name in snake case, and returns the response as a model. Models take their fields as an array, in snake case, and have a getter and a setter for each.

The API Reference lists every endpoint with its parameters and response: the SDK’s methods take and return the same ones.

Authentication

Pass a Configuration to the classes:

use LicenseManager\Api\LicensesApi; use LicenseManager\Configuration; // With an API key, from your backend: $config = (new Configuration())->setApiKey("x-api-key", getenv("LICENSEMANAGER_API_KEY")); // Or with a token scoped to a customer, license or machine: $config = (new Configuration())->setAccessToken($token); $licenses = new LicensesApi(config: $config);

Never ship an API key in your application: anyone could extract it. Keep it on your servers.

Examples

Create a license after a sale, and email its key to the customer:

use LicenseManager\Model\CreateLicense; $license = $licenses->createLicense("x7Kp2QaZ", new CreateLicense([ "email" => "jane@example.com", "send_key" => true, ]));

Validate a key from your application, which needs no credentials:

use LicenseManager\Model\ValidateKey; $licenseToken = (new LicensesApi())->validateKey("x7Kp2QaZ", new ValidateKey([ "key" => "7KQ2M-X9ZPA-H4TRC-WN6EY-B3JDF", "fingerprint" => "4c:32:75:8f:9a:1e", "version" => "1.4.2", ])); // $licenseToken->getLicense() is the signed license token.

List the licenses of a product, one page at a time:

$page = $licenses->listLicenses("x7Kp2QaZ", page: 2, page_size: 50, sort: "-createdAt"); // $page->getData() holds the licenses, $page->getPagination() the totals.

Errors

A failed request throws a LicenseManager\ApiException, holding the status and the body with the error’s stable code:

use LicenseManager\ApiException; try { $licenses->getLicense("l3Nv8KwB"); } catch (ApiException $error) { // The body is { "error": { "code", "message" } }. echo $error->getCode(), " ", $error->getResponseBody(); }