PHP code example of fingerprint / fingerprint-pro-server-api-sdk

1. Go to this page and download the library: Download fingerprint/fingerprint-pro-server-api-sdk 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/ */

    

fingerprint / fingerprint-pro-server-api-sdk example snippets




ngerprint Secret API Key
const FP_API_SECRET = "Fingerprint Secret API Key";
// An optional visitorId of a specific visitor
const FP_VISITOR_ID = "visitorId";
// An optional eventId made by a specific visitor
const FP_EVENT_ID = "requestId";

// An optional linkedId of the visit
const FP_LINKED_ID = "linkedId";
// An optional parameter limiting scanned results
const LIMIT = 10;
// An optional parameter used to paginate results, see lastTimestamp
const PAGINATION_KEY = "1683900801733.Ogvu1j";

// Import Fingerprint Server PHP SDK Classes and Guzzle Http Client
use Fingerprint\ServerSdk\Api\FingerprintApi;
use Fingerprint\ServerSdk\Configuration;
use Fingerprint\ServerSdk\Model\EventUpdate;
use GuzzleHttp\Client;

// Create a new Configuration instance with your Fingerprint Server API Key and your Fingerprint Server API Region.
/**
 * You can specify a region on second parameter
 * If you leave the second parameter empty, then Configuration::REGION_GLOBAL will be used as a default region
 * Options for regions are:
 * Configuration::REGION_EUROPE
 * Configuration::REGION_GLOBAL
 * Configuration::REGION_ASIA
 */
$config = new Configuration(FP_API_SECRET, Configuration::REGION_EUROPE);
$client = new FingerprintApi(
    $config,
    new Client(), // This is optional. Default: GuzzleHttp\Client
);

// Get an event with a given eventId
try {
    // Fetch the event with a given eventId
    list($event, $response) = $client->getEventWithHttpInfo(FP_EVENT_ID);
    echo "<pre>" . $response->getBody()->getContents() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->getEventWithHttpInfo: ', $e->getMessage(), PHP_EOL;
}

// Search for specific events
try {
    // Search events for given visitor id marked as suspicious and "bad" bot
    list($model, $response) = $client->searchEventsWithHttpInfo(LIMIT, visitor_id: FP_VISITOR_ID, bot: SearchEventsBot::BAD, suspect: true);
    // Use pagination key to get the next page
    // list($model, $response) = $client->searchEventsWithHttpInfo(LIMIT, pagination_key: $model->getPaginationKey(), visitor_id: FP_VISITOR_ID, bot: SearchEventsBot::BAD, suspect: true);
    echo "<pre>" . $response->getBody()->getContents() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->searchEventsWithHttpInfo: ', $e->getMessage(), PHP_EOL;
}

// Update Event
try {
    $body = new EventUpdate([
        'linked_id' => 'new linked id',
        'tags' => ['new_property' => 'new value'],
        'suspect' => true,
    ]);
    list($model, $response) = $client->updateEventWithHttpInfo($body, FP_EVENT_ID);
    echo "<pre>" . $response->getBody()->getContents() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->updateEventWithHttpInfo: ', $e->getMessage(), PHP_EOL;
}

// Delete by visitor ID
try {
    list($model, $response) = $client->deleteVisitorDataWithHttpInfo(FP_VISITOR_ID);
    echo "<pre>" . $response->getBody()->getContents() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->deleteVisitorDataWithHttpInfo: ', $e->getMessage(), PHP_EOL;
}



use Fingerprint\ServerSdk\Sealed\DecryptionAlgorithm;
use Fingerprint\ServerSdk\Sealed\DecryptionKey;
use Fingerprint\ServerSdk\Sealed\Sealed;

ntResponse($sealed_result, [new DecryptionKey($sealed_key, DecryptionAlgorithm::AES_256_GCM)]);

    fwrite(STDOUT, sprintf("Unsealed event: %s \n", $data));
} catch (Exception $e) {
    fwrite(STDERR, sprintf("Exception when unsealing event: %s\n", $e->getMessage()));
    exit(1);
}



use Fingerprint\ServerSdk\ObjectSerializer;
use Fingerprint\ServerSdk\Model\Event;

// $webhookData is the raw JSON string from the incoming webhook request body
$event = ObjectSerializer::deserialize(
    json_decode($webhookData),
    Event::class
);



use Fingerprint\ServerSdk\Webhook\WebhookVerifier;

// Your webhook signing secret.
$webhookSecret = "secret";

// Request data. In real life scenario this will be the body of incoming request
$webhookData = "data";

// Value of the "fpjs-event-signature" header.
$webhookHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db";

$isValidWebhookSign = WebhookVerifier::isValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);

if(!$isValidWebhookSign) {
    fwrite(STDERR, sprintf("Webhook signature verification failed\n"));
    exit(1);
}