PHP code example of elvesora / enrichment-php

1. Go to this page and download the library: Download elvesora/enrichment-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

elvesora / enrichment-php example snippets




lvesora\Enrichment\Client;

$apiKey = getenv('ELVESORA_ENRICHMENT_API_KEY');

if (!is_string($apiKey) || trim($apiKey) === '') {
    throw new RuntimeException('ELVESORA_ENRICHMENT_API_KEY is not configured.');
}

$client = new Client($apiKey);

$result = $client->enrich(
    domain: 'acme.com',
    idempotencyKey: 'company-acme-20260803',
);

echo $result->data['company_name'] ?? $result->domain;
echo $result->credits->remaining;

use Elvesora\Enrichment\Exception\ApiException;

try {
    $result = $client->enrich('example.com');
} catch (ApiException $exception) {
    if ($exception->statusCode !== 400) {
        throw $exception;
    }

    echo $exception->resultType;
    echo $exception->credits?->consumedByRequest; // 0 when metadata is present
}

use Elvesora\Enrichment\Exception\AuthenticationException;
use Elvesora\Enrichment\Exception\EnrichmentException;
use Elvesora\Enrichment\Exception\IdempotencyConflictException;
use Elvesora\Enrichment\Exception\UsageLimitException;
use Elvesora\Enrichment\Exception\ValidationException;

try {
    $result = $client->enrich('acme.com', 'company-acme-20260803');
} catch (InvalidArgumentException $exception) {
    // Invalid local configuration or input; no request was sent.
} catch (AuthenticationException $exception) {
    // The API rejected an invalid or revoked API key.
} catch (ValidationException $exception) {
    $errors = $exception->errors();
} catch (UsageLimitException $exception) {
    $limit = $exception->limit();
    $remaining = $exception->remaining();
} catch (IdempotencyConflictException $exception) {
    // The same key was previously used for another domain.
} catch (EnrichmentException $exception) {
    if ($exception->retryable) {
        $retryAfter = $exception->retryAfter;
    }
}

$client = new Client(
    apiKey: $apiKey,
    baseUrl: 'https://enrichment.elvesora.com/api/v1',
    timeout: 130,
    connectTimeout: 10,
    userAgent: 'MyApplication/1.0',
);