|
| 1 | +import io.github.cdimascio.dotenv.Dotenv; |
| 2 | +import java.io.IOException; |
| 3 | +import java.util.concurrent.TimeUnit; |
| 4 | +import okhttp3.*; |
| 5 | +import org.json.JSONObject; |
| 6 | + |
| 7 | +public class BatchDelete { |
| 8 | + |
| 9 | + // Specify your API key here, or in the environment variable PDFREST_API_KEY. |
| 10 | + // You can also put the environment variable in a .env file. |
| 11 | + private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; |
| 12 | + |
| 13 | + public static void main(String[] args) { |
| 14 | + |
| 15 | + final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load(); |
| 16 | + |
| 17 | + RequestBody requestBody = |
| 18 | + new MultipartBody.Builder() |
| 19 | + .setType(MultipartBody.FORM) |
| 20 | + .addFormDataPart( |
| 21 | + "ids", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") |
| 22 | + .build(); |
| 23 | + Request request = |
| 24 | + new Request.Builder() |
| 25 | + .header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY)) |
| 26 | + .url("https://api.pdfrest.com/delete") |
| 27 | + .post(requestBody) |
| 28 | + .build(); |
| 29 | + try { |
| 30 | + OkHttpClient client = |
| 31 | + new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build(); |
| 32 | + Response response = client.newCall(request).execute(); |
| 33 | + System.out.println("Result code " + response.code()); |
| 34 | + if (response.body() != null) { |
| 35 | + System.out.println(prettyJson(response.body().string())); |
| 36 | + } |
| 37 | + } catch (IOException e) { |
| 38 | + throw new RuntimeException(e); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + private static String prettyJson(String json) { |
| 43 | + // https://stackoverflow.com/a/9583835/11996393 |
| 44 | + return new JSONObject(json).toString(4); |
| 45 | + } |
| 46 | +} |
0 commit comments