SDKs

JavaScript SDK quickstart

Dieser Leitfaden ist noch nicht in Ihre Sprache übersetzt.

Client for the LegalCloud API: read your legal documents, sites, resources and statistics, and embed documents in any JS/TS application (Node, serverless, bundlers).

  • Version 1.1.0 · Node 18+ (global fetch) · ES module + CommonJS · TypeScript types included · no dependencies
  • 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 and install the folder:

unzip legalcloud_sdk-js-1.1.0.zip
npm install ./legalcloud

Quick start

import { LegalCloudClient } from '@legalcloud/sdk';      // or: const { LegalCloudClient } = require('@legalcloud/sdk');

const client = new LegalCloudClient({ token: 'lc_...', source: 'express', siteUrl: 'https://example.com' });

const { documents, total } = await client.listDocuments({ page: 1, perPage: 20 });
for await (const doc of client.iterDocuments()) console.log(doc.id, doc.title);

const html = await client.getDocument('abc123def456', 'es');                 // HTML of /d/{hash}
const iframe = client.iframeHtml('abc123def456', { lang: 'es', height: 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.

Options

OptionDefaultMeaning
tokenrequiredAPI token (Authorization: Bearer)
sourcecustomPlatform that embeds LegalCloud (analytics)
siteUrlwindow.location.origin or ''Public URL of your site (analytics)
pluginIdgeneratedStable id of this installation (analytics)
baseUrlhttps://api.legalcloud.infoAPI origin
embedBaseUrlbaseUrl if given, else https://dash.legalcloud.infoOrigin of /d/{hash} pages
timeout15000Milliseconds per request
maxRetries2Retries for 429, 5xx and network errors
backoff500Base milliseconds of the exponential backoff (a Retry-After header wins; capped at 30 s)
fetchglobal fetchCustom fetch implementation

Methods

Every method returns the data of the API envelope ({"success": true, "data": ...}).

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({page, perPage, siteId}) · iterDocuments()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({type, siteId, page, perPage}) · iterResources() · getResourceUsage() · getResourceStatistics()GET /api/resources...resources:read
getStats({days}) · getKpis() · getViews({documentHash, 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.lastQuota (X-Quota-Limit/Remaining/Reset, monthly plan quota) and client.lastRateLimit (X-RateLimit-*, per minute) hold the latest values.

import { RateLimitError, NotFoundError, LegalCloudError } from '@legalcloud/sdk';

try {
  await client.getDocumentInfo('missing');
} catch (e) {
  if (e instanceof NotFoundError) { /* ... */ }
  else if (e instanceof RateLimitError) console.log(e.retryAfter, e.quota, e.rateLimit);
  else if (e instanceof LegalCloudError) console.log(e.message);   // base class
}
ErrorWhen
ValidationError400 / 422
AuthenticationError401: missing, invalid, revoked or expired token
PermissionDeniedError403: scope missing or feature not in the plan (e.code: SCOPE_FORBIDDEN, PLAN_UPGRADE_REQUIRED...)
NotFoundError404
RateLimitError429: monthly quota or per-minute limit (e.retryAfter seconds)
ServerError5xx
NetworkErrorno HTTP response

ApiError (all but NetworkError) exposes status, code, body, quota, rateLimit, retryAfter.

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. Never ship a full-scope token in browser code.

Next steps

Zuletzt aktualisiert: 2026-10-27

Lebenslang KOSTENLOS registrieren, ohne Kreditkarte

Kostenloses Konto erstellen