我正在尝试通过Google Apps脚本将采购订单信息从Zoho Books拉到Google表格中。
我是App脚本的新手,所以我一直在拼凑一些代码,但是没有返回任何内容,任何想法?
function Zoho() {
var ss = SpreadsheetApp.getActiveSpreadsheet(); //get active spreadsheet (bound to this script)
var sheet = ss.getSheetByName('Sheet1'); //The name of the sheet tab where you are sending the info
var zohoOauthToken = "mytoken";
var zohoOrganization = "myorg";
var zohoUrl = [
"https://books.zoho.com/api/v3/salesorders?",
"organization_id=", zohoOrganization,
"&authtoken=", zohoOauthToken,
].join("");
try{
var response = UrlFetchApp.fetch(zohoUrl); // get api endpoint
var json = response.getContentText(); // get the response content as text
var Sheet1 = JSON.parse(json); //parse text into json
Logger.log(Sheet1); //log data to logger
var stats=[]; //create empty array to hold data points
sheet.appendRow(stats);
}
catch (error) {
Logger.log(error.toString());
}
}
答案 0 :(得分:1)
您现在无疑已经为自己解决了这个问题,但是对于其他正在寻找答案的人....
zUrl = 'https://books.zoho.com/api/v3/';
zToken = '?authtoken=##############################';
zOrgId = '&organization_id=#########';
function getPurchaseorderById(iD) {
//iD = "##############"
var result = UrlFetchApp.fetch(zUrl + 'purchaseorders/' + iD + zToken);
//var PO = parse(result).purchaseorder;
return parse(result).purchaseorder;
}
function getOpenPurchaseOrders(){
var result = UrlFetchApp.fetch(zUrl + 'purchaseorders/' + zToken + '&status=issued&sort_column=delivery_date&sort_order=A');
//var PO = parse(result).purchaseorder;
return parse(result).purchaseorders;
}
function getOpenPurchaseOrdersByDate(date){
var date = toZohoDate(date);
var result = UrlFetchApp.fetch(zUrl + 'purchaseorders/' + zToken + '&date=' + date);
//var POs = parse(result);
return parse(result).purchaseorders;
}
function toZohoDate(date) {
return Utilities.formatDate(new Date(date), "GMT", "yyyy-MM-dd");
}
function parse(x){
return JSON.parse(x.getContentText());
}
用于不同的模块。...
function getInvoiceByNumber(num){
//num='#####';
var result = UrlFetchApp.fetch(zUrl + 'invoices/' + zToken + "&search_text=" + num);
//var inv = parse(result).invoices[0];
return parse(result);
}