Intégration SDK PHP
Installation (Packagist) :
bash
composer require veilio/sdkSource : VeilioAPI/veilio-sdk-php. Avant Packagist : composer require veilio/sdk:dev-main avec un repository VCS pointant sur ce GitHub.
Exemple :
bash
<?php
require __DIR__ . '/vendor/autoload.php';
use Veilio\Sdk\VeilioClient;
$veilio = new VeilioClient(
apiKey: getenv('VEILIO_API_KEY') ?: '',
baseUrl: getenv('VEILIO_BASE_URL') ?: 'https://app.veilio.fr/api',
);
function createCustomer(VeilioClient $veilio, string $email): array
{
$result = $veilio->tokenize(data: $email, type: 'email');
// Stocker le token en base, jamais l’e-mail en clair.
return ['email_token' => $result['token']];
}
function sendWelcomeEmail(VeilioClient $veilio, string $emailToken): string
{
$original = $veilio->detokenize(
token: $emailToken,
reason: 'Send welcome email',
);
return $original['data'];
}
function deleteUserData(VeilioClient $veilio, string $emailToken): void
{
$veilio->shredToken(
token: $emailToken,
reason: 'GDPR - user deletion request',
);
}Configuration du client
typescript
$veilio = new VeilioClient(
apiKey: string, // Obligatoire
baseUrl: string = 'https://app.veilio.fr/api',
timeout: int = 30, // secondes
maxRetries: int = 3,
);On-premise :
bash
$veilio = new VeilioClient(
apiKey: getenv('VEILIO_API_KEY') ?: '',
baseUrl: 'https://your-domain.com/api',
);| Variable | Description |
|---|---|
VEILIO_API_KEY | Clé API du dashboard Veilio |
VEILIO_BASE_URL | URL de base API (optionnel, défaut SaaS) |
Référence API
tokenize(...) — POST /tokenize
bash
$result = $veilio->tokenize(
data: 'john@example.com',
type: 'email',
metadata: ['source' => 'signup'],
retention: ['ttlDays' => 30],
);
$phone = $veilio->tokenize(
data: '0612345678',
type: 'phone',
mode: 'fpt',
entityId: 'BP10042',
);
// $phone['token'] === '0600000000'tokenizeBulk(fields, entityId?) — POST /tokenize/bulk
bash
$result = $veilio->tokenizeBulk(
fields: [
['data' => 'john@example.com', 'type' => 'email', 'mode' => 'fpt'],
['data' => '+33612345678', 'type' => 'phone', 'mode' => 'fpt'],
['data' => 'Ada Lovelace', 'type' => 'firstName'],
],
entityId: 'BP10042',
);detokenize(...) — POST /detokenize
bash
$result = $veilio->detokenize(
token: 'tok_abc123...',
reason: 'Send email',
username: 'alice.dupont', // utilisateur final de VOTRE app (audit)
);
$phone = $veilio->detokenize(
token: '0600000000',
entityId: 'BP10042',
reason: 'Partner screen',
);detokenizeBulk(...) — POST /detokenize/bulk
bash
$result = $veilio->detokenizeBulk(
tokens: [
['token' => '00000000@example.com'],
['token' => '0600000000'],
['token' => '000000000', 'type' => 'siren'],
],
entityId: 'BP10042',
reason: 'Profile view',
username: 'alice.dupont',
);shredToken / shredBulk — POST /tokens/shred, POST /tokens/shred-bulk
bash
$veilio->shredToken(token: 'tok_abc123...', reason: 'GDPR delete request');
$veilio->shredBulk(
ids: ['cuid_1', 'cuid_2'],
reason: 'Batch erasure',
);
// ou par entityId partenaire :
$veilio->shredBulk(entityId: 'BP10042', reason: 'Close partner file');lookup(value, type?) — POST /lookup
Égalité exacte via blind index. Renvoie des jetons, jamais le clair.
bash
$hits = $veilio->lookup(value: 'john@example.com', type: 'email');tokenizeFormat / detokenizeFormat — JSON / CSV / SQL
bash
$fmt = $veilio->tokenizeFormat(
data: json_encode(['email' => 'john@example.com']),
format: 'json',
options: ['fields' => ['email'], 'retention' => ['ttlDays' => 365]],
);
$restored = $veilio->detokenizeFormat(
tokenizedData: $fmt['tokenizedData'],
format: 'json',
tokens: $fmt['tokens'],
);Documents (PDF / Office)
previewDocument, tokenizeDocument, detokenizeDocument, listDocuments, storeDocument, getDocument, deleteDocument. Guide : Documents tokenisés.
bash
$file = file_get_contents('./letter.pdf');
$preview = $veilio->previewDocument($file, kind: 'pdf');
$stored = $veilio->storeDocument(
entityId: 'letter-2026-001',
file: $file,
fileName: 'letter.pdf',
spanSelection: ['includeIndices' => [0, 1]],
);
$masked = $veilio->getDocument($stored['id']);Gestion des erreurs
typescript
use Veilio\Sdk\Exception\AuthenticationException;
use Veilio\Sdk\Exception\PlanLimitException;
use Veilio\Sdk\Exception\RateLimitException;
use Veilio\Sdk\Exception\TokenShreddedException;
use Veilio\Sdk\Exception\VeilioException;
try {
$veilio->detokenize(token: 'tok_…', reason: 'Support case');
} catch (AuthenticationException $e) {
// 401
} catch (RateLimitException $e) {
// 429 — $e->retryAfter
} catch (PlanLimitException $e) {
// 403
} catch (TokenShreddedException $e) {
// 410
} catch (VeilioException $e) {
// $e->getErrorCode(), $e->statusCode
}| Code | HTTP | Description |
|---|---|---|
AUTH_ERROR | 401 | Clé API invalide ou absente |
VALIDATION_ERROR | 400 | Corps de requête invalide |
PLAN_LIMIT | 403 | Quota plan atteint |
RATE_LIMIT_ERROR | 429 | Rate limit |
TOKEN_SHREDDED | 410 | Jeton détruit cryptographiquement |
TIMEOUT_ERROR | 408 | Timeout |
INTERNAL_ERROR | 5xx | Erreur serveur |
Prérequis
- PHP 8.1+
ext-curl,ext-json- Une clé API Veilio valide
Liens
- Packagist : https://packagist.org/packages/veilio/sdk (après submit)
- Source : https://github.com/VeilioAPI/veilio-sdk-php
- Référence HTTP : Intégration HTTP