From a93e33282fb050c0370bc47b2da99211ff27b351 Mon Sep 17 00:00:00 2001 From: Christopher Green Date: Thu, 6 Jun 2024 13:29:34 -0500 Subject: [PATCH] Update request-status.php sample --- .gitignore | 2 + .../Multipart Payload/request-status.php | 38 ++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index e66cd32..d5178b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1287,3 +1287,5 @@ FodyWeavers.xsd Node/node_modules/ Node/package-lock.json +PHP/**/vendor/** +PHP/**/composer.* diff --git a/PHP/Endpoint Examples/Multipart Payload/request-status.php b/PHP/Endpoint Examples/Multipart Payload/request-status.php index f8849a6..10859c5 100644 --- a/PHP/Endpoint Examples/Multipart Payload/request-status.php +++ b/PHP/Endpoint Examples/Multipart Payload/request-status.php @@ -5,19 +5,47 @@ use GuzzleHttp\Psr7\Request; // Import the PSR-7 Request class. use GuzzleHttp\Psr7\Utils; // Import the PSR-7 Utils class for working with streams. -$client = new Client(); // Create a new instance of the Guzzle HTTP client. +$client = new Client(); // Create a new instance of the Guzzle HTTP client -$requestId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // place the requestId returned from a previous POST request here +$apiKey = 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Your API key goes here. + +$headers = [ + 'Api-Key' => $apiKey, + 'response-type' => 'requestId' +]; + +$pngOptions = [ + 'multipart' => [ + [ + 'name' => 'file', + 'contents' => Utils::tryFopen('/path/to/file.pdf', 'r'), + 'filename' => 'file.pdf', + 'headers' => [ + 'Content-Type' => '' + ] + ] + ] +]; + +$pngRequest = new Request('POST', 'https://api.pdfrest.com/png', $headers); + +$pngResponse = $client->sendAsync($pngRequest, $pngOptions)->wait(); + +echo $pngResponse->getBody(); +echo "\r\n"; + +$requestId = json_decode($pngResponse->getBody())->{'requestId'}; $request_status_endpoint_url = 'https://api.pdfrest.com/request-status/'.$requestId; $headers = [ - 'Api-Key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Set the API key in the headers for authentication. + 'Api-Key' => $apiKey ]; -$request = new Request('GET', $request_status_endpoint_url, $headers); // Create a new HTTP GET request with the API endpoint and headers. +$request = new Request('GET', $request_status_endpoint_url, $headers); -$res = $client->sendAsync($request)->wait(); // Send the asynchronous request and wait for the response. +$res = $client->sendAsync($request)->wait(); echo $res->getBody(); // Output the response body, which contains the status information. +echo "\r\n"; ?>