-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeliverable-basic.php
More file actions
87 lines (75 loc) · 2.83 KB
/
Copy pathdeliverable-basic.php
File metadata and controls
87 lines (75 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Deliverable SDK - Basic Usage Example
*
* This example demonstrates the complete deliverable workflow:
* 1. Configure the SDK
* 2. Generate a deliverable from a template
* 3. List deliverables
* 4. Get deliverable details
* 5. Download the source file and PDF
* 6. Update a deliverable
*/
require_once __DIR__ . '/../vendor/autoload.php';
use TurboDocx\Config\DeliverableConfig;
use TurboDocx\Deliverable;
// 1. Configure with your API credentials
Deliverable::configure(new DeliverableConfig(
apiKey: $_ENV['TURBODOCX_API_KEY'],
orgId: $_ENV['TURBODOCX_ORG_ID'],
));
// 2. Generate a deliverable from a template
echo "Generating deliverable...\n";
$created = Deliverable::generateDeliverable([
'templateId' => 'YOUR_TEMPLATE_ID',
'name' => 'Employee Contract - John Smith',
'description' => 'Employment contract for senior developer',
'variables' => [
['placeholder' => '{EmployeeName}', 'text' => 'John Smith', 'mimeType' => 'text'],
['placeholder' => '{CompanyName}', 'text' => 'TechCorp Solutions Inc.', 'mimeType' => 'text'],
['placeholder' => '{JobTitle}', 'text' => 'Senior Software Engineer', 'mimeType' => 'text'],
],
'tags' => ['hr', 'contract', 'employee'],
]);
$deliverableId = $created['results']['deliverable']['id'];
echo "Created deliverable: {$deliverableId}\n";
// 3. List deliverables
echo "\nListing deliverables...\n";
$list = Deliverable::listDeliverables([
'limit' => 5,
'showTags' => true,
'column0' => 'createdOn',
'order0' => 'desc',
]);
echo "Found {$list['totalRecords']} deliverables\n";
foreach ($list['results'] as $d) {
echo " - {$d['name']} ({$d['id']})\n";
}
// 4. Get full details
echo "\nGetting deliverable details...\n";
$details = Deliverable::getDeliverableDetails($deliverableId, showTags: true);
echo "Name: {$details['name']}\n";
echo "Template: {$details['templateName']}\n";
echo "Variables: " . count($details['variables'] ?? []) . "\n";
$tagNames = array_map(fn($t) => $t['label'], $details['tags'] ?? []);
echo "Tags: " . implode(', ', $tagNames) . "\n";
// 5. Download files
echo "\nDownloading source file...\n";
$sourceFile = Deliverable::downloadSourceFile($deliverableId);
file_put_contents('contract.docx', $sourceFile);
echo "Saved contract.docx\n";
echo "Downloading PDF...\n";
$pdfFile = Deliverable::downloadPDF($deliverableId);
file_put_contents('contract.pdf', $pdfFile);
echo "Saved contract.pdf\n";
// 6. Update the deliverable
echo "\nUpdating deliverable...\n";
$updated = Deliverable::updateDeliverableInfo($deliverableId, [
'name' => 'Employee Contract - John Smith (Final)',
'tags' => ['hr', 'contract', 'finalized'],
]);
echo $updated['message'] . "\n";
// 7. Delete the deliverable (soft delete)
// $deleted = Deliverable::deleteDeliverable($deliverableId);
// echo $deleted['message'] . "\n";
echo "\nDone!\n";