/
exported-form-data.php
39 lines (32 loc) · 1.73 KB
/
exported-form-data.php
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
<?php
require 'vendor/autoload.php'; // Require the autoload file to load Guzzle HTTP client.
use GuzzleHttp\Client; // Import the Guzzle HTTP client namespace.
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.
$headers = [
'Api-Key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Set the API key in the headers for authentication.
];
$options = [
'multipart' => [
[
'name' => 'file', // Specify the field name for the file.
'contents' => Utils::tryFopen('/path/to/file', 'r'), // Open the file specified by the '/path/to/file' for reading.
'filename' => '/path/to/file', // Set the filename for the file to be processed, in this case, '/path/to/file'.
'headers' => [
'Content-Type' => '<Content-type header>' // Set the Content-Type header for the file.
]
],
[
'name' => 'data_format', // Specify the field name for the data file format.
'contents' => 'xml' // Set the value for the data file format (in this case, 'xml').
],
[
'name' => 'output', // Specify the field name for the output option.
'contents' => 'pdfrest_exported_form_data' // Set the value for the output option (in this case, 'pdfrest_exported_form_data').
]
]
];
$request = new Request('POST', 'https://api.pdfrest.com/exported-form-data', $headers); // Create a new HTTP POST request with the API endpoint and headers.
$res = $client->sendAsync($request, $options)->wait(); // Send the asynchronous request and wait for the response.
echo $res->getBody(); // Output the response body, which contains the exported form data content.