|
| 1 | +<?php |
| 2 | +require 'vendor/autoload.php'; // Require the autoload file to load Guzzle HTTP client. |
| 3 | + |
| 4 | +use GuzzleHttp\Client; // Import the Guzzle HTTP client namespace. |
| 5 | +use GuzzleHttp\Psr7\Request; // Import the PSR-7 Request class. |
| 6 | +use GuzzleHttp\Psr7\Utils; // Import the PSR-7 Utils class for working with streams. |
| 7 | + |
| 8 | +// By default, we use the US-based API service. This is the primary endpoint for global use. |
| 9 | +$apiUrl = "https://api.pdfrest.com"; |
| 10 | + |
| 11 | +/* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. |
| 12 | + * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work |
| 13 | + */ |
| 14 | +//$apiUrl = "https://eu-api.pdfrest.com"; |
| 15 | + |
| 16 | +$upload_client = new Client(['http_errors' => false]); |
| 17 | +$upload_headers = [ |
| 18 | + 'api-key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', |
| 19 | + 'content-filename' => 'filename.pdf', |
| 20 | + 'Content-Type' => 'application/octet-stream' |
| 21 | +]; |
| 22 | +$upload_body = file_get_contents('/path/to/file'); |
| 23 | +$upload_request = new Request('POST', $apiUrl.'/upload', $upload_headers, $upload_body); |
| 24 | +$upload_res = $upload_client->sendAsync($upload_request)->wait(); |
| 25 | +echo $upload_res->getBody() . PHP_EOL; |
| 26 | + |
| 27 | +$upload_response_json = json_decode($upload_res->getBody()); |
| 28 | + |
| 29 | +$uploaded_id = $upload_response_json->{'files'}[0]->{'id'}; |
| 30 | + |
| 31 | +echo "Successfully uploaded with an id of: " . $uploaded_id . PHP_EOL; |
| 32 | + |
| 33 | +$tdm_reserved_pdf_client = new Client(['http_errors' => false]); |
| 34 | +$tdm_reserved_pdf_headers = [ |
| 35 | + 'api-key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', |
| 36 | + 'Content-Type' => 'application/json' |
| 37 | +]; |
| 38 | +$tdm_reserved_pdf_body = '{"id":"'.$uploaded_id.'", "policy":"https://example.com/tdm-policy"}'; |
| 39 | +$tdm_reserved_pdf_request = new Request('POST', $apiUrl.'/tdm-reserved-pdf', $tdm_reserved_pdf_headers, $tdm_reserved_pdf_body); |
| 40 | +$tdm_reserved_pdf_res = $tdm_reserved_pdf_client->sendAsync($tdm_reserved_pdf_request)->wait(); |
| 41 | +echo $tdm_reserved_pdf_res->getBody() . PHP_EOL; |
0 commit comments