我正在尝试使用电子表格中的数据生成发票,而且我对HTTPS请求不是很熟悉,更不用说谷歌的UrlFetchApp了。我正在尝试将API提供的this example code转换成AppsScript可以使用的东西。到目前为止,它只是将网站作为.html保存到文件夹中。
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."
}发布于 2021-11-22 21:09:10
您需要在UrlFetchApp.fetch参数中使用full link,如下所示:
var response = UrlFetchApp.fetch('https://invoice-generator.com', options);这将以PDF格式返回正确的响应:

https://stackoverflow.com/questions/70070859
复制相似问题