Skip to content

Commit

Permalink
Update request-status.php sample
Browse files Browse the repository at this point in the history
  • Loading branch information
datalogics-cgreen committed Jun 6, 2024
1 parent a07fa7a commit a93e332
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1287,3 +1287,5 @@ FodyWeavers.xsd

Node/node_modules/
Node/package-lock.json
PHP/**/vendor/**
PHP/**/composer.*
38 changes: 33 additions & 5 deletions PHP/Endpoint Examples/Multipart Payload/request-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<Content-type header>'
]
]
]
];

$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";
?>

0 comments on commit a93e332

Please sign in to comment.