SDKs

PHP SDK quickstart

Esta guía todavía no está traducida a tu idioma: se muestra en inglés.

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 on https://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 / optionDefaultMeaning
$tokenrequiredAPI token (Authorization: Bearer)
$sourcecustomPlatform that embeds LegalCloud (analytics)
$siteUrl''Public URL of your site (analytics)
$pluginIdgeneratedStable id of this installation (analytics)
$baseUrlhttps://api.legalcloud.infoAPI origin
embedBaseUrl$baseUrl if given, else https://dash.legalcloud.infoOrigin of /d/{hash} pages
timeout15Seconds per request
maxRetries2Retries for 429, 5xx and network errors
backoff0.5Base 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...).

MethodEndpointScope
getDocument($hash, $lang)GET /d/{hash}public / document token
getDocumentRestrictions($hash, $country)GET /d/{hash}/restrictionspublic
publicUrl($hash, $lang, $includeToken) · iframeHtml($hash, $lang, $height, $includeToken)(builds URLs / HTML)-
listDocuments([...]) · iterDocuments($perPage)GET /api/documentsdocuments:read
getDocumentInfo($hash)GET /api/documents/{hash}documents:read
getDocumentLanguages() · getDocumentLimits()GET /api/documents/languages, /limitsdocuments: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
ValidationException400 / 422
AuthenticationException401: missing, invalid, revoked or expired token
PermissionDeniedException403: scope missing or feature not in the plan (getErrorCode(): SCOPE_FORBIDDEN, PLAN_UPGRADE_REQUIRED...)
NotFoundException404
RateLimitException429: monthly quota or per-minute limit (getRetryAfter() seconds)
ServerException5xx
NetworkExceptionno 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.

Next steps

Última actualización: 2026-10-27

Regístrate GRATIS de por vida, sin tarjeta de crédito

Crear cuenta gratis