Skip to content

Quickstart

In this tutorial, you connect your application to your sandbox organization, open the case (dossier) of a property sale with its two clients, a buyer named Camille Durand SANCTION and a seller, launch their analyses, and end by reading the three sanctions alerts the buyer raised. You use a terminal and a browser, then, for the code, Node.js 20 or later, PHP 8.1 or later, or curl alone. The first three steps run in the terminal whatever language you choose.

You need what your developer account gives you when you create your application in its console (or LexOpti, when it registers it for you):

  • a LexOpti account, created with the e-mail address you develop with, that owns a sandbox organization;
  • an OAuth client: its client_id, its client_secret (shown once) and one of its registered redirect URIs. This tutorial writes it https://crm.example.com/oauth/callback: use yours instead.

Developer and professional accounts are separate: if you already use LexOpti as a professional, ask for these with another e-mail address.

LexOpti always requires PKCE. In your terminal, keep your client’s credentials and draw a random verifier, then compute its challenge:

Terminal window
export CLIENT_ID=YOUR_CLIENT_ID
export CLIENT_SECRET=YOUR_CLIENT_SECRET
export CODE_VERIFIER=$(openssl rand -base64 32 | tr '+/' '-_' | tr -d '=')
export CODE_CHALLENGE=$(printf %s "$CODE_VERIFIER" | openssl dgst -sha256 -binary | openssl base64 | tr '+/' '-_' | tr -d '=')
echo "$CODE_CHALLENGE"

The last command prints a 43-character challenge. Keep this terminal open: the next steps use these variables.

Open this address in your browser, with your client_id, your redirect URI and the challenge you just printed:

https://app.lexopti.com/api/auth/oauth2/authorize?response_type=code
&client_id=YOUR_CLIENT_ID
&redirect_uri=https://crm.example.com/oauth/callback
&code_challenge=YOUR_CODE_CHALLENGE&code_challenge_method=S256
&scope=openid%20offline_access%20lexopti:read%20lexopti:write
&resource=https://app.lexopti.com/v1&state=YOUR_STATE

Sign in with your developer account, pick your sandbox organization and consent. LexOpti sends your browser to your redirect URI with code and state in the address. Your callback does not need to exist yet: copy the value of code from the address bar, and use it at once, since a code is valid for a short time and only once.

Terminal window
export CODE=THE_CODE_YOU_COPIED
Terminal window
curl https://app.lexopti.com/api/auth/oauth2/token \
-u "$CLIENT_ID:$CLIENT_SECRET" \
-d grant_type=authorization_code \
-d code="$CODE" \
-d code_verifier="$CODE_VERIFIER" \
-d redirect_uri=https://crm.example.com/oauth/callback \
-d resource=https://app.lexopti.com/v1

LexOpti answers a JSON object with an access_token, valid 15 minutes (expires_in: 900), and a refresh_token. Keep the access token for the rest of the tutorial:

Terminal window
export LEXOPTI_ACCESS_TOKEN=THE_ACCESS_TOKEN
curl -H "Authorization: Bearer $LEXOPTI_ACCESS_TOKEN" https://app.lexopti.com/v1/organization

The answer describes your sandbox organization, with "sandbox": true: your application now acts for you in it.

Write the next steps in the language of your choice: the tabs show each one in TypeScript with the SDK, in PHP with its curl extension and no library, or with curl in the same terminal.

In LexOpti, an analysis always runs in a case (dossier): the matter, engagement or operation it is run for, with its nature and its clients. Here the case is a property sale, an example many professions handle, of nature vente_immobiliere, for two clients, the buyer and the seller. A case names existing clients, so you create them first (POST /v1/clients), then the case (POST /v1/cases). SANCTION in the buyer’s last name gives a deterministic sanctions hit in the sandbox; the seller’s name is clean. Each creation sends an Idempotency-Key (the SDK adds it), so that a retry never creates a second resource.

The natures depend on the profession of your sandbox: lawyers and estate agents offer vente_immobiliere; for another profession, pick one of its own (an accountant’s sandbox may use cession_parts_actions, for instance), or custom with a type_label, which every profession offers, a notary’s included.

In a new folder, install the SDK:

Terminal window
npm install @lexopti/sdk

Save this script as quickstart.mts:

import { createLexOptiClient } from "@lexopti/sdk";
const lexopti = createLexOptiClient({
accessToken: () => process.env.LEXOPTI_ACCESS_TOKEN ?? "",
});
const organization = await lexopti.organization.get();
const buyer = await lexopti.clients.create({
type: "person",
person: {
first_name: "Camille",
last_name: "Durand SANCTION",
birth_date: "1980-02-01",
nationalities: ["FR"],
},
});
const seller = await lexopti.clients.create({
type: "person",
person: {
first_name: "Louis",
last_name: "Martin",
birth_date: "1975-06-15",
nationalities: ["FR"],
},
});
const sale = await lexopti.cases.create({
types: ["vente_immobiliere"],
clients: [{ id: buyer.id }, { id: seller.id }],
label: "Vente 12 rue des Lilas",
});
console.log(organization.sandbox, sale.id, sale.type);

Run it from the terminal where LEXOPTI_ACCESS_TOKEN is set:

Terminal window
npx tsx quickstart.mts

The script prints true (your organization is a sandbox), the id of the case and its nature vente_immobiliere; with curl, the answer is the case itself (201). Nothing is screened yet: its pending_alert_count is 0.

One call launches the case’s analyses, as the « Lancer les analyses » button of LexOpti does on the case page: every client and party of the case is screened across the sources, and each client gets a check of your own. (To create a case and launch its analyses in one call, send launch_checks: true with POST /v1/cases.)

Add these lines at the end of quickstart.mts, then run the script again:

const launch = await lexopti.cases.launchChecks({ id: sale.id });
console.log(
launch.checks.length,
launch.checks.map((check) => check.status).join(" ")
);

A script run again creates a second case, with two new sandbox clients. The new line gives the number of checks launched, one per client of the case, and the status of each; with curl, the answer is the case itself (202), with its checks. A check is asynchronous: your integration follows it, or waits for check.completed.

Add these lines at the end of quickstart.mts, then run the script again:

const checks = await Promise.all(
launch.checks.map((check) => lexopti.checks.get({ id: check.id }))
);
const settled = await lexopti.cases.get({ id: sale.id });
const buyerAlerts = await lexopti.alerts.list({ client_id: buyer.id });
const sellerAlerts = await lexopti.alerts.list({ client_id: seller.id });
console.log(
checks.map((check) => check.status).join(" "),
settled.pending_alert_count,
sellerAlerts.data.length
);
for (const alert of buyerAlerts.data) {
console.log(alert.status, alert.source);
}

This time you read both checks completed, the three alerts the case counts for a member to review (pending_alert_count), and none for the seller; then the buyer’s alerts, pending, one per sanctions source: international_sanctions, eu_sanctions and french_asset_freezes, in any order. A member reviews them in LexOpti, on the case.

You have authorized an application, opened a case with its clients through the API, launched its analyses and read what they found, as a member would see it in LexOpti.