SDKs

Authentication with bearer tokens

Dieser Leitfaden ist noch nicht in Ihre Sprache übersetzt.

The SDKs authenticate with an API token that you create in the dashboard. This page explains which token to use and how the SDKs send it.

Which token to use

ScenarioToken
Your server reads documents and renders themAn application token (scope documents:read is enough)
Your server also reads sites, resources or account dataAn application token with sites:read, resources:read or organization:read as needed
A browser iframe must open a document that requires an access tokenA document token for that document

See API tokens to create them. Never put an application token in code that runs in the visitor's browser.

How the SDKs send the token

getDocument() calls GET https://dash.legalcloud.info/d/{hash}?lang={lang}; the other methods call https://api.legalcloud.info/api/.... All of them send these headers:

HeaderValue
AuthorizationBearer <token>
X-LegalCloud-SourceThe integration source you configure (custom, drupal, magento, prestashop, shopify…)
X-LegalCloud-SiteThe URL of your website
X-LegalCloud-Plugin-IdA unique id of your installation (generated automatically if you do not pass one)
X-LegalCloud-VersionThe version of your integration

iframeHtml() builds an iframe whose address contains the token as ?token=…, because a browser iframe cannot send headers. Use a document token for this case: it can only open that one document, so a leaked iframe address exposes nothing else. The token appears in server logs and in the browser history, which is why an application token must never be used here.

Configuration

OptionRequiredDescription
tokenyesYour API token
sourceyes (JS: recommended)Source name for analytics
site URLyes (JS: optional)The URL of the website that embeds the document
plugin idnoUnique id of the installation; generated if omitted. Keep it stable between requests
versionnoVersion of your integration (default: the SDK version)
base URLnoAPI origin, default https://api.legalcloud.info
embed base URLnoOrigin of the public /d/{hash} pages, default https://dash.legalcloud.info

Error handling

If the document does not exist, is not published, the visitor's country or your site is not allowed, the scope is missing or the token is wrong, LegalCloud answers with an HTTP error (401, 403, 404, 429; see Errors reference). Every SDK maps the status to a specific error class: AuthenticationError (401), PermissionDeniedError (403, with the code SCOPE_FORBIDDEN or PLAN_UPGRADE_REQUIRED), NotFoundError (404), ValidationError (400 / 422), RateLimitError (429, with the seconds to wait and the quota headers) and ServerError (5xx). They share a base class (LegalCloudError in JavaScript and Python, LegalCloudException in PHP), so one catch handles all of them. 429 and 5xx are retried automatically first.

Next steps

Zuletzt aktualisiert: 2026-10-27

Lebenslang KOSTENLOS registrieren, ohne Kreditkarte

Kostenloses Konto erstellen