Documentation Index
Fetch the complete documentation index at: https://docs.dragdropdo.com/llms.txt
Use this file to discover all available pages before exploring further.
Installation
composer require dragdropdo/sdk
Quick start
<?php
require 'vendor/autoload.php';
use DragdropdoSdk\Dragdropdo;
// Initialize the client
$client = new Dragdropdo([
'api_key' => 'your-api-key-here',
'base_url' => 'https://api.dragdropdo.com', // Optional, defaults to https://api.dragdropdo.com
'timeout' => 30000 // Optional, defaults to 30000ms
]);
// Upload a file
$uploadResult = $client->uploadFile([
'file' => '/path/to/document.pdf',
'file_name' => 'document.pdf',
'mime_type' => 'application/pdf',
]);
echo "File key: " . $uploadResult['file_key'] . "\n";
Initialization
new Dragdropdo(array $config)
Config:
api_key (required) – your D3 API key.
base_url (optional) – API base URL, default: https://api.dragdropdo.com.
timeout (optional) – request timeout in ms, default: 30000.
headers (optional) – additional headers to send with every request.
File upload
uploadFile(array $options): array
Options:
file (required) – file path string.
file_name (required) – original file name.
mime_type (optional) – MIME type (auto‑detected if omitted).
parts (optional) – number of upload parts (auto‑calculated).
on_progress (optional) – progress callback.
Example:
$result = $client->uploadFile([
'file' => '/path/to/file.pdf',
'file_name' => 'document.pdf',
'mime_type' => 'application/pdf',
'on_progress' => function($progress) {
echo "Upload: {$progress['percentage']}%\n";
}
]);
Supported operations
checkSupportedOperation(array $options): array
Options:
ext (required) – file extension (e.g. pdf, jpg).
action (optional) – specific action (convert, compress, …).
parameters (optional) – parameters to validate (e.g. ['convert_to' => 'png']).
Examples:
// Get available actions for PDF
$actions = $client->checkSupportedOperation(['ext' => 'pdf']);
echo implode(', ', $actions['available_actions']) . "\n";
// Check if convert to PNG is supported
$supported = $client->checkSupportedOperation([
'ext' => 'pdf',
'action' => 'convert',
'parameters' => ['convert_to' => 'png']
]);
echo "Supported: " . ($supported['supported'] ? 'true' : 'false') . "\n";
Create operations
createOperation(array $options): array
Options:
action (required) – "convert" | "compress" | "merge" | "zip" | "lock" | "unlock" | "reset_password".
file_keys (required) – array of file keys from upload.
parameters (optional) – action‑specific parameters.
notes (optional) – user metadata.
Examples:
// Convert PDF to PNG
$client->createOperation([
'action' => 'convert',
'file_keys' => [$uploadResult['file_key']],
'parameters' => ['convert_to' => 'png'],
'notes' => ['userId' => 'user-123']
]);
// Compress
$client->createOperation([
'action' => 'compress',
'file_keys' => [$uploadResult['file_key']],
'parameters' => ['compression_value' => 'recommended']
]);
Convenience helpers
The client exposes shorthand helpers:
$client->convert($fileKeys, $convertTo, $notes = null);
$client->compress($fileKeys, $compressionValue = 'recommended', $notes = null);
$client->merge($fileKeys, $notes = null);
$client->zip($fileKeys, $notes = null);
$client->lockPdf($fileKeys, $password, $notes = null);
$client->unlockPdf($fileKeys, $password, $notes = null);
$client->resetPdfPassword($fileKeys, $oldPassword, $newPassword, $notes = null);
Status & polling
getStatus(array $options): array
pollStatus(array $options): array
getStatus options (same shape as single‑fetch inputs for polling):
main_task_id (required) – main task ID from createOperation / convenience helpers.
file_key (optional) – when set, requests status for that specific input file.
pollStatus options (includes all getStatus keys, plus polling controls):
main_task_id (required), file_key (optional) – as above.
interval (optional) – milliseconds between polls, default 2000.
timeout (optional) – maximum total polling time in milliseconds, default 300000 (5 minutes).
on_update (optional) – callable receiving the status array after each successful fetch.
Examples:
// Single status fetch
$status = $client->getStatus(['main_task_id' => 'task-123']);
// Poll until completion
$finalStatus = $client->pollStatus([
'main_task_id' => 'task-123',
'interval' => 2000,
'timeout' => 300000,
'on_update' => function($status) {
echo "Status: {$status['operation_status']}\n";
}
]);
Complete workflow example
<?php
require 'vendor/autoload.php';
use DragdropdoSdk\Dragdropdo;
use DragdropdoSdk\Exceptions\D3APIError;
use DragdropdoSdk\Exceptions\D3ValidationError;
function processFile() {
$client = new Dragdropdo([
'api_key' => getenv('D3_API_KEY'),
'base_url' => 'https://api.dragdropdo.com'
]);
try {
// 1. Upload
$uploadResult = $client->uploadFile([
'file' => './document.pdf',
'file_name' => 'document.pdf'
]);
// 2. Check support
$supported = $client->checkSupportedOperation([
'ext' => 'pdf',
'action' => 'convert',
'parameters' => ['convert_to' => 'png']
]);
if (!$supported['supported']) {
throw new Exception('Convert to PNG is not supported');
}
// 3. Create operation
$operation = $client->convert(
[$uploadResult['file_key']],
'png',
['userId' => 'user-123', 'source' => 'api']
);
// 4. Poll
$status = $client->pollStatus([
'main_task_id' => $operation['main_task_id'],
'interval' => 2000
]);
if ($status['operation_status'] === 'completed') {
foreach ($status['files_data'] as $file) {
echo "Download: {$file['download_link']}\n";
}
}
} catch (D3APIError $e) {
echo "API Error ({$e->getStatusCode()}): {$e->getMessage()}\n";
} catch (D3ValidationError $e) {
echo "Validation Error: {$e->getMessage()}\n";
} catch (Exception $e) {
echo "Error: {$e->getMessage()}\n";
}
}
processFile();