Estoy tratando de generar una factura utilizando datos de mi hoja de cálculo y no estoy muy familiarizado con las solicitudes HTTPS, y mucho menos con UrlFetchApp de Google. Estoy tratando de convertir este código de ejemplo provisto por la API en algo que AppsScript pueda usar. Hasta ahora, solo guarda el sitio web como .html en la carpeta.
function debug(){ run(); } const folderName = 'Invoices Test' function generateInvoice(invoice) { var postData = JSON.stringify(invoice); var options = { 'method' : "post", 'contentType': "application/json", 'payload': postData }; // Make a POST request with a JSON payload. var response = UrlFetchApp.fetch('invoice-generator.com', options); var fileBlob = response.getBlob(); var folderID = getInvoiceFolderID(); var folder = DriveApp.getFolderById(folderID); var result = folder.createFile(fileBlob); } /** * @return String */ function getInvoiceFolderID(){ var id; var folders = DriveApp.getFoldersByName(folderName); if(!folders.hasNext()){ DriveApp.createFolder(folderName).getId(); } else{ id = folders.next().getId() } return id; } var invoice = { logo: "http://invoiced.com/img/logo-invoice.png", from: "Invoiced\n701 Brazos St\nAustin, TX 78748", to: "Johnny Appleseed", currency: "usd", number: "INV-0001", payment_terms: "Auto-Billed - Do Not Pay", items: [ { name: "Subscription to Starter", quantity: 1, unit_cost: 50 } ], fields: { tax: "%" }, tax: 5, notes: "Thanks for being an awesome customer!", terms: "No need to submit payment. You will be auto-billed for this invoice." }Debe usar el enlace completo en el parámetro UrlFetchApp.fetch , de la siguiente manera:
var response = UrlFetchApp.fetch('https://invoice-generator.com', options);Esto devolvería la respuesta correcta en formato PDF: