Dieser Leitfaden ist noch nicht in Ihre Sprache übersetzt.
PHP client for the LegalCloud API: read your legal documents, sites, resources and statistics, and embed documents in any PHP application (Laravel, Symfony, Drupal, Magento, PrestaShop, plain PHP...). No WordPress required.
- Version 1.1.0 · PHP 7.4+ ·
ext-curl,ext-json· PSR-4 (LegalCloud\) - Default API origin
https://api.legalcloud.info; public pages onhttps://dash.legalcloud.info
Install
The SDK is distributed as a ZIP from your dashboard (Downloads). Unzip it next to your project.
With Composer (a path repository):
unzip legalcloud_sdk-php-1.1.0.zip -d vendor-local/
composer config repositories.legalcloud path vendor-local/legalcloud
composer require legalcloud/sdk:@dev
Without Composer:
require '/path/to/legalcloud/src/autoload.php';
Quick start
use LegalCloud\Client;
$client = new Client('lc_...', 'laravel', 'https://example.com');
$page = $client->listDocuments(['page' => 1, 'per_page' => 20]); // ['documents' => [...], 'total' => ...]
foreach ($client->iterDocuments() as $doc) { // generator, every page
echo $doc['id'], ' ', $doc['title'], "\n";
}
$html = $client->getDocument('abc123def456', 'es'); // HTML of /d/{hash}
$iframe = $client->iframeHtml('abc123def456', 'es', 600);
Create the token in the dashboard (Organization > API). A document token only opens its own document; to call the rest of the API use a token with the scopes shown below.
Constructor
new Client(string $token, string $source = 'custom', string $siteUrl = '', ?string $pluginId = null, ?string $version = null, ?string $baseUrl = null, array $options = [])
| Argument / option | Default | Meaning |
|---|---|---|
$token | required | API token (Authorization: Bearer) |
$source | custom | Platform that embeds LegalCloud (analytics) |
$siteUrl | '' | Public URL of your site (analytics) |
$pluginId | generated | Stable id of this installation (analytics) |
$baseUrl | https://api.legalcloud.info | API origin |
embedBaseUrl | $baseUrl if given, else https://dash.legalcloud.info | Origin of /d/{hash} pages |
timeout | 15 | Seconds per request |
maxRetries | 2 | Retries for 429, 5xx and network errors |
backoff | 0.5 | Base seconds of the exponential backoff (a Retry-After header wins; capped at 30 s) |
Methods
Every method returns the data of the API envelope ({"success": true, "data": ...}) as an array. Query parameters are passed as arrays with the API names (page, per_page, site_id...).
| Method | Endpoint | Scope |
|---|---|---|
getDocument($hash, $lang) | GET /d/{hash} | public / document token |
getDocumentRestrictions($hash, $country) | GET /d/{hash}/restrictions | public |
publicUrl($hash, $lang, $includeToken) · iframeHtml($hash, $lang, $height, $includeToken) | (builds URLs / HTML) | - |
listDocuments([...]) · iterDocuments($perPage) | GET /api/documents | documents:read |
getDocumentInfo($hash) | GET /api/documents/{hash} | documents:read |
getDocumentLanguages() · getDocumentLimits() | GET /api/documents/languages, /limits | documents:read |
listDocumentVersions($hash, [...]) · getDocumentVersion($hash, $n) · diffDocumentVersions($hash, $from, $to) | GET /api/documents/{hash}/versions... | documents:read |
listSites() · getSite($id) · getSiteLimits() | GET /api/sites... | sites:read |
listResources([...]) · iterResources() · getResourceUsage() · getResourceStatistics() | GET /api/resources... | resources:read |
getStats($days) · getKpis() · getViews($hash, $days) · getDocumentStats($hash, $days) · getDocumentVisits($hash, $page, $limit, $days) · getSourceBreakdown($hash, $days) · getTopSites($hash, $days) | GET /api/statistics/... | documents:read |
listTokens() · getApiUsage() · listApiCalls([...]) | GET /api/account/... | organization:read |
The SDK covers the read endpoints. Creating, editing and deleting content is done in the dashboard.
Quota and errors
After every call $client->getLastQuota() (X-Quota-Limit/Remaining/Reset, monthly plan quota) and $client->getLastRateLimit() (X-RateLimit-*, per minute) hold the latest values.
use LegalCloud\Exception\{NotFoundException, RateLimitException, LegalCloudException};
try {
$client->getDocumentInfo('missing');
} catch (NotFoundException $e) {
// ...
} catch (RateLimitException $e) {
echo $e->getRetryAfter(), json_encode($e->getQuota());
} catch (LegalCloudException $e) { // base class: network errors, API errors...
echo $e->getMessage();
}
Exception (LegalCloud\Exception\) | When |
|---|---|
ValidationException | 400 / 422 |
AuthenticationException | 401: missing, invalid, revoked or expired token |
PermissionDeniedException | 403: scope missing or feature not in the plan (getErrorCode(): SCOPE_FORBIDDEN, PLAN_UPGRADE_REQUIRED...) |
NotFoundException | 404 |
RateLimitException | 429: monthly quota or per-minute limit (getRetryAfter() seconds) |
ServerException | 5xx |
NetworkException | no HTTP response |
ApiException (parent of all but NetworkException) exposes getStatus(), getErrorCode(), getApiMessage(), getBody(), getQuota(), getRateLimit(), getRetryAfter().
Security
iframeHtml() puts the token in the URL by default (the only way an iframe can authenticate). That URL ends up in logs and browser history: use a document token for embeds, or pass $includeToken = false for public documents.