I'm trying to get a proof-of-concept working before purchasing your product. Our product is running in MS Powerapps. I have Javascript code that retrieves a PDF form from an API, then I want to populate the form fields with some data. I'm trying to call the Plumsail "fill-form" API to do that, passing the file as a blob object and data as JSON. I get a link returned that is valid (I can paste it into my browser and it downloads the PDF). But when I try to retrieve the file in JS code, I get this error:
Access to fetch at 'https://actions.blob.core.windows.net/data-storage/2021-10-01_yej3zx5j.t3j.pdf?sv=2020-08-04&se=2021-10-01T22%3A18%3A16Z&sr=b&sp=r&rscd=inline&sig=4gYwkDn1qqWObL41geXfk3cPwX5LisXM8OFL0gSOv14%3D' from origin 'https://spearclaimsdev.crm.dynamics.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
When I add "mode: 'no-cors'" to the request header, it returns an empty file, and no error. Can you help me to get this working? My Javascript code is below.
Thanks.
My code:
var myHeaders = new Headers();
myHeaders.append("Authorization", "<my API Key>");
var formdata = new FormData();
formdata.append("File", blobPDF);
formdata.append("Data", "{\"DN43\":\"Sabadell\",\"DN44\":\"Danny\", ... etc.}");
formdata.append("Locale", "en-US");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://api.plumsail.com/api/v2/pdf/fill-form", requestOptions)
.then(response => response.text())
.then(result => {
const obj = JSON.parse(result);
var link = obj.link;
var requestOptions = {
method: 'POST',
mode: "no-cors"
};
fetch(link, requestOptions)
.then(res => res.blob()) // Gets the response and returns it as a blob
.then(blobPopulatedPDF => {
// this is where blobPopulatedPDF is empty
})
.catch(error => {
// handle error conditions
var alertStrings = {
confirmButtonLabel: "OK",
text: "Error retrieving populated form from link (" + link + "): " + error.message,
title: "Error Encountered"
};
Xrm.Navigation.openAlertDialog(alertStrings);
});
})
.catch(error => {
// handle error conditions
var alertStrings = {
confirmButtonLabel: "OK",
text: "Error retrieving retrieving Plumsail link: " + error.message,
title: "Error Encountered"
};
Xrm.Navigation.openAlertDialog(alertStrings);
});