friends. Using Google Apps Script, I created a system that creates a Google document and a PDF document from the data entered in a Google table. I need to make it so that after the PDF document is created, it is sent via a link to a webhook. I implemented this through a method ‘UrlFetchApp.fetch’, but when I enter data into the table and run the script, nothing works with this method, even documents do not want to be created. I tried everything possible, nothing works, please help.
const pdfBlob = DriveApp.getFileById(copy.getId()).getAs('application/pdf');
const pdfFile = destinationFolder.createFile(pdfBlob);
pdfFile.setName(`Document ${rowData[3]} ${rowData[4]} ${rowData[5]}.pdf`);
const docUrl = doc.getUrl();
const pdfUrl = pdfFile.getUrl();
sheet.getRange(row, 14).setValue(docUrl);
sheet.getRange(row, 15).setValue(pdfUrl);
const webhookUrl="https://webhook.site/cef34a00-844b-4f51-8c72-dae4bcf79239";
const fileBlob = pdfBlob.getBlob();
var options = {
method: 'post',
contentType: 'application/pdf',
payload: fileBlob.getBytes(),
//payload: pdfBlob.getBytes() //also doesnt work
muteHttpExceptions: true
};
try {
var response = UrlFetchApp.fetch(webhookUrl, options);
Logger.log('Response code: ' + response.getResponseCode());
Logger.log('Response content: ' + response.getContentText());
} catch (error) {
Logger.log('Error: ' + error.message);
}
You need to sign in to view this answers
Leave feedback about this