From 8896bdb4644b5b9b793a61aa9eb4a40958d1ec4d Mon Sep 17 00:00:00 2001 From: Eric Shore Date: Thu, 25 Apr 2024 14:06:41 -0500 Subject: [PATCH 1/8] Create request-status.sh Adds new cURL example for /request-status endpoint --- cURL/Endpoint Examples/Multipart Payload/request-status.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 cURL/Endpoint Examples/Multipart Payload/request-status.sh diff --git a/cURL/Endpoint Examples/Multipart Payload/request-status.sh b/cURL/Endpoint Examples/Multipart Payload/request-status.sh new file mode 100644 index 0000000..b7463dd --- /dev/null +++ b/cURL/Endpoint Examples/Multipart Payload/request-status.sh @@ -0,0 +1,2 @@ +curl -X GET "https://api.pdfrest.com/request-status/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ + -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" From 35a4a5c0ba35d1f02d0632af5e9f1a5d187f9c41 Mon Sep 17 00:00:00 2001 From: Eric Shore Date: Thu, 25 Apr 2024 14:09:12 -0500 Subject: [PATCH 2/8] Create request-status.py Add request-status Python example --- .../Multipart Payload/request-status.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Python/Endpoint Examples/Multipart Payload/request-status.py diff --git a/Python/Endpoint Examples/Multipart Payload/request-status.py b/Python/Endpoint Examples/Multipart Payload/request-status.py new file mode 100644 index 0000000..4aa28ee --- /dev/null +++ b/Python/Endpoint Examples/Multipart Payload/request-status.py @@ -0,0 +1,24 @@ +from requests_toolbelt import MultipartEncoder +import requests +import json + +api_polling_endpoint_url = 'https://api.pdfrest.com/request-status' + +request_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place requestId to poll here + +api_polling_endpoint_url = f'https://api.pdfrest.com/request-status/{request_id}' + +headers = { + 'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here +} + +print("Sending GET request to request-status endpoint...") +response = requests.get(api_polling_endpoint_url, headers=headers) + +print("Response status code: " + str(response.status_code)) + +if response.ok: + response_json = response.json() + print(json.dumps(response_json, indent = 2)) +else: + print(response.text) From d03f5394dd5424f876a758d379214ea1fb2ac042 Mon Sep 17 00:00:00 2001 From: Eric Shore Date: Thu, 25 Apr 2024 14:15:30 -0500 Subject: [PATCH 3/8] Create request-status.php Add request-status PHP example --- .../Multipart Payload/request-status.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 PHP/Endpoint Examples/Multipart Payload/request-status.php diff --git a/PHP/Endpoint Examples/Multipart Payload/request-status.php b/PHP/Endpoint Examples/Multipart Payload/request-status.php new file mode 100644 index 0000000..f8849a6 --- /dev/null +++ b/PHP/Endpoint Examples/Multipart Payload/request-status.php @@ -0,0 +1,23 @@ + 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Set the API key in the headers for authentication. +]; + +$request = new Request('GET', $request_status_endpoint_url, $headers); // Create a new HTTP GET request with the API endpoint and headers. + +$res = $client->sendAsync($request)->wait(); // Send the asynchronous request and wait for the response. + +echo $res->getBody(); // Output the response body, which contains the status information. +?> From de81467cc8b05e70a19eb4a2dc3df7307078c533 Mon Sep 17 00:00:00 2001 From: Eric Shore Date: Thu, 25 Apr 2024 14:18:43 -0500 Subject: [PATCH 4/8] Create request-status.js Add request-status JavaScript example --- .../Multipart Payload/request-status.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 JavaScript/Endpoint Examples/Multipart Payload/request-status.js diff --git a/JavaScript/Endpoint Examples/Multipart Payload/request-status.js b/JavaScript/Endpoint Examples/Multipart Payload/request-status.js new file mode 100644 index 0000000..d397067 --- /dev/null +++ b/JavaScript/Endpoint Examples/Multipart Payload/request-status.js @@ -0,0 +1,18 @@ +const axios = require("axios"); + +let config = { + method: "get", + maxBodyLength: Infinity, // set maximum length of the request body + url: "https://api.pdfrest.com/request-status/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", + headers: { "Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } +}; + +// define configuration options for axios request +axios + .request(config) + .then((response) => { + console.log(JSON.stringify(response.data)); + }) + .catch((error) => { + console.log(error); + }); From f7c142e2e9f380129afd3c0ddf599af49e54d9a9 Mon Sep 17 00:00:00 2001 From: Eric Shore Date: Thu, 25 Apr 2024 14:20:32 -0500 Subject: [PATCH 5/8] Create request-status.cs Add request-status C# example for .NET --- .../Multipart Payload/request-status.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 DotNET/Endpoint Examples/Multipart Payload/request-status.cs diff --git a/DotNET/Endpoint Examples/Multipart Payload/request-status.cs b/DotNET/Endpoint Examples/Multipart Payload/request-status.cs new file mode 100644 index 0000000..cd9dbd5 --- /dev/null +++ b/DotNET/Endpoint Examples/Multipart Payload/request-status.cs @@ -0,0 +1,17 @@ +using System.Text; + +using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) +{ + string requestId = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // requestId to poll + using (var request = new HttpRequestMessage(HttpMethod.Get, "request-status" + requestId)) + { + request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); + + var response = await httpClient.SendAsync(request); + + var apiResult = await response.Content.ReadAsStringAsync(); + + Console.WriteLine("API response received."); + Console.WriteLine(apiResult); + } +} From b89209dd243806399ec52d117b90f28843bb827b Mon Sep 17 00:00:00 2001 From: Eric Shore Date: Thu, 25 Apr 2024 14:33:45 -0500 Subject: [PATCH 6/8] Create RequestStatus.java Add request-status Java example --- .../Multipart Payload/RequestStatus.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Java/Endpoint Examples/Multipart Payload/RequestStatus.java diff --git a/Java/Endpoint Examples/Multipart Payload/RequestStatus.java b/Java/Endpoint Examples/Multipart Payload/RequestStatus.java new file mode 100644 index 0000000..193cbca --- /dev/null +++ b/Java/Endpoint Examples/Multipart Payload/RequestStatus.java @@ -0,0 +1,49 @@ +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.json.JSONObject; + +public class RequestStatus { + + // Request UUIDs can be found in the JSON response of POST requests as "requestId" when API Polling is enabled. + // Resource UUIDs usually look like this: '0950b9bdf-0465-4d3f-8ea3-d2894f1ae839'. + private static final String REQUEST_ID = + "2e3c603d1-30b2-4c16-8c11-911a51bb2ba9"; // place requestID here + + // Specify your API key here, or in the environment variable PDFREST_API_KEY. + // You can also put the environment variable in a .env file. + private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; + +public static void main(String[] args) { + + final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load(); + + String urlString = + String.format("https://api.pdfrest.com/request-status/%s", REQUEST_ID); + + Request request = + new Request.Builder() + .header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY)) + .url(urlString) + .get() + .build(); + try { + OkHttpClient client = + new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build(); + Response response = client.newCall(request).execute(); + System.out.println("Result code " + response.code()); + if (response.body() != null) { + System.out.println(prettyJson(response.body().string())); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static String prettyJson(String json) { + // https://stackoverflow.com/a/9583835/11996393 + return new JSONObject(json).toString(4); + } +} From d9c4754131a8cb06d308a6453ce34c63c078f045 Mon Sep 17 00:00:00 2001 From: "Kevin A. Mitchell" Date: Thu, 25 Apr 2024 15:16:22 -0500 Subject: [PATCH 7/8] RequestStatus: Fix up imports --- .../Multipart Payload/RequestStatus.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Java/Endpoint Examples/Multipart Payload/RequestStatus.java b/Java/Endpoint Examples/Multipart Payload/RequestStatus.java index 193cbca..a9d1548 100644 --- a/Java/Endpoint Examples/Multipart Payload/RequestStatus.java +++ b/Java/Endpoint Examples/Multipart Payload/RequestStatus.java @@ -1,8 +1,10 @@ import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; + +import io.github.cdimascio.dotenv.Dotenv; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.json.JSONObject; public class RequestStatus { From 4c533754049f08b66bab1fd7d3ba1b50d9a6267f Mon Sep 17 00:00:00 2001 From: "Kevin A. Mitchell" Date: Thu, 25 Apr 2024 15:20:35 -0500 Subject: [PATCH 8/8] RequestStatus.java: Apply Spotless to format code --- .../Multipart Payload/RequestStatus.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Java/Endpoint Examples/Multipart Payload/RequestStatus.java b/Java/Endpoint Examples/Multipart Payload/RequestStatus.java index a9d1548..916cf61 100644 --- a/Java/Endpoint Examples/Multipart Payload/RequestStatus.java +++ b/Java/Endpoint Examples/Multipart Payload/RequestStatus.java @@ -1,7 +1,6 @@ +import io.github.cdimascio.dotenv.Dotenv; import java.io.IOException; import java.util.concurrent.TimeUnit; - -import io.github.cdimascio.dotenv.Dotenv; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -9,7 +8,8 @@ public class RequestStatus { - // Request UUIDs can be found in the JSON response of POST requests as "requestId" when API Polling is enabled. + // Request UUIDs can be found in the JSON response of POST requests as "requestId" when API + // Polling is enabled. // Resource UUIDs usually look like this: '0950b9bdf-0465-4d3f-8ea3-d2894f1ae839'. private static final String REQUEST_ID = "2e3c603d1-30b2-4c16-8c11-911a51bb2ba9"; // place requestID here @@ -18,13 +18,12 @@ public class RequestStatus { // You can also put the environment variable in a .env file. private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; -public static void main(String[] args) { + public static void main(String[] args) { final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load(); - - String urlString = - String.format("https://api.pdfrest.com/request-status/%s", REQUEST_ID); - + + String urlString = String.format("https://api.pdfrest.com/request-status/%s", REQUEST_ID); + Request request = new Request.Builder() .header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY))