PHP code example of scanlyser / php-sdk

1. Go to this page and download the library: Download scanlyser/php-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/ */

    

scanlyser / php-sdk example snippets


use ScanLyser\Client;
use ScanLyser\Enums\ScanCategory;

$client = new Client(apiKey: 'your-api-token');

// List your sites
$sites = $client->sites($teamId)->list();

foreach ($sites->data as $site) {
    echo "{$site->name}: {$site->url}\n";
}

// Trigger a scoped scan. Omit categories to assess all five public categories.
$scan = $client->scans($teamId)->trigger(
    $siteId,
    wcagLevel: 'AA',
    categories: [ScanCategory::Accessibility, ScanCategory::SEO],
);

// Wait for completion
$scan = $client->scans($teamId)->awaitCompletion($scan->id);

// Get issues
$issues = $client->issues($teamId)->list($scan->id, severity: 'critical');

// Inspect scanner diagnostics independently from findings
$diagnostics = $client->diagnostics($teamId)->list($scan->id);

$client = new Client(
    apiKey: 'your-api-token',
    maxRetries: 3, // optional, retries on 429
);

$teams = $client->teams()->list();
$team = $client->teams()->get($teamId);

$sites = $client->sites($teamId)->list(perPage: 15);
$site = $client->sites($teamId)->create(name: 'My Site', url: 'https://example.com');
$site = $client->sites($teamId)->get($siteId);
$client->sites($teamId)->delete($siteId);

use ScanLyser\Enums\ScanCategory;

$scans = $client->scans($teamId)->list($siteId);
$scan = $client->scans($teamId)->trigger(
    $siteId,
    wcagLevel: 'AA',
    webhookUrl: 'https://example.com/webhooks/scanlyser',
    categories: [ScanCategory::SEO, ScanCategory::Performance],
);
$scan = $client->scans($teamId)->get($scanId);

// Poll until complete (default: 600s timeout, 10s interval)
$scan = $client->scans($teamId)->awaitCompletion(
    $scanId,
    timeoutSeconds: 600,
    pollIntervalSeconds: 10,
);

if ($scan->hasUsableScore()) {
    echo "Score: {$scan->scores->overall}\n";
} else {
    echo "Outcome: {$scan->assessmentOutcome?->value}\n";
}

if ($scan->hasUsableCategoryScore(ScanCategory::SEO)) {
    echo "SEO: {$scan->scores->seo}\n";
} else {
    $seoOutcome = $scan->categoryCoverage?->for(ScanCategory::SEO)->outcome->value ?? 'unavailable';
    echo "SEO: {$seoOutcome}\n";
}

$pages = $client->pages($teamId)->list($scanId);
$page = $client->pages($teamId)->get($scanId, $pageId);

$issues = $client->issues($teamId)->list($scanId);
$issues = $client->issues($teamId)->list($scanId, category: 'wcag', severity: 'critical');

use ScanLyser\Enums\ResultOutcome;

$result = $issues->data[0]->result;

if ($result->outcome === ResultOutcome::ManualReview) {
    echo $result->explanation->reasoning;
}

$diagnostics = $client->diagnostics($teamId)->list($scanId, perPage: 50, page: 2);

foreach ($diagnostics->data as $diagnostic) {
    echo "{$diagnostic->code}: {$diagnostic->detail->message} ({$diagnostic->correlationId})\n";
}

$report = $client->reports($teamId)->json($scanId);
$client->reports($teamId)->pdf($scanId, saveTo: '/path/to/report.pdf');

use ScanLyser\Webhooks\WebhookSignature;

$isValid = WebhookSignature::verify(
    payload: $request->getContent(),
    signature: $request->header('X-Signature'),
    secret: $tokenHash,
);

use ScanLyser\Exceptions\AuthenticationException;
use ScanLyser\Exceptions\ForbiddenException;
use ScanLyser\Exceptions\NotFoundException;
use ScanLyser\Exceptions\RateLimitException;
use ScanLyser\Exceptions\ValidationException;

try {
    $site = $client->sites($teamId)->get('nonexistent');
} catch (NotFoundException $exception) {
    // 404
} catch (ValidationException $exception) {
    // 422 - $exception->errors contains field-level errors
} catch (RateLimitException $exception) {
    // 429 - automatic retries exhausted
}

use ScanLyser\Client;

class ScanController extends Controller
{
    public function trigger(Client $client): void
    {
        $scan = $client->scans(config('scanlyser.team_id'))
            ->trigger($siteId, wcagLevel: 'AA');
    }
}
bash
composer 
bash
php artisan vendor:publish --tag=scanlyser-config