Skip to content

Commit

Permalink
Update request-status.js sample
Browse files Browse the repository at this point in the history
  • Loading branch information
datalogics-cgreen committed Jun 6, 2024
1 parent ba58d15 commit 6804bb7
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions JavaScript/Endpoint Examples/Multipart Payload/request-status.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");

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" }

const apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Replace with your API key
const pathToFile = "/path/to/file.pdf";

let bmpRequestData = new FormData();
bmpRequestData.append("file", fs.createReadStream(pathToFile));

let bmpConfig = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/bmp",
headers: {
"Api-Key": apiKey,
"Response-Type": "requestId", // Use this header to get a request ID.
...bmpRequestData.getHeaders(),
},
data: bmpRequestData,
};

// define configuration options for axios request
axios
.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
axios(bmpConfig)
.then(bmpResponse => {
console.log(JSON.stringify(bmpResponse.data));
const requestId = bmpResponse.data.requestId;
let config = {
method: "get",
maxBodyLength: Infinity, // set maximum length of the request body
url: `https://api.pdfrest.com/request-status/${requestId}`,
headers: { "Api-Key": apiKey }
};
axios.request(config)
.then((requestStatusResponse) => {
console.log(JSON.stringify(requestStatusResponse.data));
})
.catch((error) => {
console.log(error);
});
}).catch(error => {
console.log(error);
});
})

0 comments on commit 6804bb7

Please sign in to comment.