我正在尝试导入所有Pipedrive个交易,并在Google表格中写下我需要的信息。
我已经可以做的事情:访问Feed并将数据解析为变量。 并将此变量打印到1个单元格中。当然这还不可行。
代码有点被清除(在我学习的过程中构建)
// Standard functions to call the spreadsheet sheet and activesheet
function alldeals() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheet = ss.getActiveSheet();
//the way the url is build next step is to itterate between the end because api only allows a fixed number of calls (100) this way i can slowly fill the sheet.
var url = "https://api.pipedrive.com/v1/deals?start=";
var url2 = "&limit="
var start = 0;
var end = start+50;
var token = "&api_token=hiddenforobviousreasons"
//call the api and fill dataAll with the jsonparse.
//then the information is set into the
//dataSet so that i can refill datall with new data.
var response = UrlFetchApp.fetch(url+start+url2+end+token);
var dataAll = JSON.parse(response.getContentText());
var dataSet = dataAll;
//create array where the data should be put
var rows = [], data;
for (i = 0; i < dataSet.length; i++) {
data = dataSet[i];
rows.push([data.id, data.value,data.pipeline_id]); //your JSON entities here
}
dataRange = sheet.getRange(1, 1, rows.length, 3); // 3 Denotes total number of entites
dataRange.setValues(rows);
}
我在sheet.getRange
上收到的错误。
我想要实现的是将数据放在列id,value,pipeline_id
中任何指示我需要去解决这个问题的方向都会很棒!修复会很好,但是一些指针对我的理解会更有用。
我得到的错误如下:
来自afmetingen van het bereik zijn ongeldig的decoördinaten。 (regel 29,bestand'athtull5.0')
松散翻译:
到达范围的坐标无效(第29行,文件“dealpull5.0”)
答案 0 :(得分:1)
感谢这篇文章! 我重新编写了代码以满足我的一些需求,直接返回匹配交易数组。
我还将api请求更改为仅提取特定交易字段,撤回500笔交易,并使用我们设置的PipeDriver过滤器。
// Standard functions to call the spreadsheet sheet and activesheet
function GetPipedriveDeals() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheet = ss.getActiveSheet();
//the way the url is build next step is to iterate between the end because api only allows a fixed number of calls (100) this way i can slowly fill the sheet.
var url = "https://api.pipedrive.com/v1/deals:(org_name,title,owner_name,status,pipeline_id)?start=";
var limit = "&limit=500";
var filter = "&filter_id=1";
var pipeline = 7; // put a pipeline id specific to your PipeDrive setup
var start = 0;
// var end = start+50;
var token = "&api_token=your-api-token-goes-here"
//call the api and fill dataAll with the jsonparse.
//then the information is set into the
//dataSet so that i can refill datall with new data.
var response = UrlFetchApp.fetch(url+start+limit+filter+token);
var dataAll = JSON.parse(response.getContentText());
var dataSet = dataAll;
//create array where the data should be put
var rows = [], data;
for (var i = 0; i < dataSet.data.length; i++) {
data = dataSet.data[i];
if(data.pipeline_id === pipeline){
rows.push([data.org_name, data.title, data.owner_name, data.status, data.pipeline_id]);//your JSON entities here
}
}
Logger.log( JSON.stringify(rows,null,2) ); // Log transformed data
return rows;
}
答案 1 :(得分:0)
您已从Web API检索数据,并将其转换为二维数组(行数组,其中每行是一个单元格数组)。要确认这一点,您可以在修复数据的循环后添加Logger调用:
var rows = [], data;
for (i = 0; i < dataSet.length; i++) {
data = dataSet[i];
rows.push([data.id, data.value,data.pipeline_id]); //your JSON entities here
}
Logger.log( JSON.stringify(rows,null,2) ); // Log transformed data
如果你运行它,你应该在你的日志中看到这样的东西:
[--timestamp--] [
[ id1, value1, pipeline_id1 ],
[ id2, value2, pipeline_id2 ],
...
]
接下来,您要将其写入电子表格,如下所示:
A B C
1 | ID | Value | Pipeline_Id |
+------+-------+-------------+
2 | | | |
3 | | | |
错误消息抱怨数据范围和大小的大小不匹配。
注意事项:
A2
,其也表示为R2C1
。Range.setValues()
时,所提供数据的所有行的长度必须与范围的宽度相同。如有必要,您可能需要在调用Range.setValues()
之前填充或修剪数据。将范围大小与数据大小相匹配是很方便的;这样,您就可以轻松适应从API检索到的数据的变化。
var dataRange = sheet.getRange(2, 1, rows.length, rows[0].length);
dataRange.setValues(rows);