Skip to main content

PHP Examples for adaline.ink

PHP code examples for the Adaline platform API using cURL.

Examples use PHP's built-in cURL extension. No Composer packages required.

Setup

<?php
const BASE_URL = 'https://api.adaline.ink';
$accessToken = '';

function apiRequest(string $method, string $path, ?array $body = null): array {
    global $accessToken;
    $ch = curl_init(BASE_URL . $path);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $accessToken,
        'Content-Type: application/json',
    ]);
    if ($method === 'POST') {
        curl_setopt($ch, CURLOPT_POST, true);
        if ($body) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
    } elseif ($method === 'DELETE') {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
    } elseif ($method === 'PATCH') {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
        if ($body) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
    }
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true) ?? [];
}

Authentication

function login(string $email, string $password): void {
    global $accessToken;
    $result = apiRequest('POST', '/api/v1/auth/login', [
        'email' => $email,
        'password' => $password,
    ]);
    $accessToken = $result['access_token'];
}

login('you@example.com', 'your-password');

Upload a Document

function uploadDocument(string $orgId, string $filePath): array {
    global $accessToken;
    $ch = curl_init(BASE_URL . '/api/v1/documents/upload?org_id=' . $orgId);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $accessToken,
    ]);
    curl_setopt($ch, CURLOPT_POSTFIELDS, [
        'file' => new CURLFile($filePath),
    ]);
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true);
}

$doc = uploadDocument('your-org-id', 'syllabus.pdf');
echo "Uploaded: {$doc['id']} ({$doc['doc_type']})\n";

List Documents

$data = apiRequest('GET', '/api/v1/documents/?org_id=your-org-id');
foreach ($data['items'] as $doc) {
    $tags = implode(', ', array_map(fn($t) => $t['name'], $doc['tags'] ?? []));
    echo "{$doc['filename']} ({$doc['doc_type']}) - {$doc['uploaded_by_name']}\n";
    if ($tags) echo "  Tags: $tags\n";
}

Compliance Check

$report = apiRequest('POST', '/api/v1/compliance/test', [
    'document_id' => $doc['id'],
]);
echo "Score: {$report['overall_score']}% (Grade {$report['grade']})\n";

foreach ($report['checks'] as $check) {
    if (!$check['passed']) {
        echo "  [{$check['severity']}] {$check['details']}\n";
    }
}

Tags

$tag = apiRequest('POST', '/api/v1/tags', [
    'name' => 'reviewed', 'color' => 'green', 'org_id' => 'your-org-id',
]);
apiRequest('POST', "/api/v1/tags/{$tag['id']}/documents/{$doc['id']}");

Public Share

$share = apiRequest('POST', "/api/v1/documents/{$doc['id']}/public-share", []);
echo "Public link: {$share['url']}\n";

Batch Upload and Score

foreach (glob('./documents/*.{pdf,docx,pptx}', GLOB_BRACE) as $file) {
    echo "Processing " . basename($file) . "...\n";
    $doc = uploadDocument('your-org-id', $file);
    $report = apiRequest('POST', '/api/v1/compliance/test', ['document_id' => $doc['id']]);
    echo "  Score: {$report['overall_score']}% ({$report['grade']})\n";
}
© 2026 Adaline LLC