条纹api:https://www.streak.com/api/
我尝试将此条纹api与GAS UrlService一起使用,并找到了获取请求的正确语法。但我找不到put和post的严格语法:
(1)f.e。创建框
var RequestArguments = {
"contentType": "application/json",
"headers":{
"User-Agent": "MY_APP_NAME",
"Authorization": "Basic " + Utilities.base64Encode(streakApiKey),
},
"validateHttpsCertificates" :false,
"method": "PUT",
"????": "????"
};
var result = UrlFetchApp.fetch(RequestUrl,RequestArguments);
(2)f.e。编辑框
var RequestArguments = {
"contentType": "application/json",
"headers":{
"User-Agent": "MY_APP_NAME",
"Authorization": "Basic " + Utilities.base64Encode(streakApiKey),
},
"validateHttpsCertificates":false,
"method": "PUT",
"????": "????"
};
var result = UrlFetchApp.fetch(RequestUrl,RequestArguments);
答案 0 :(得分:0)
我在Chrome扩展程序中使用这种方式,没有尝试此代码,但在GAS中应该类似:
"url": "https://www.streak.com/api/v1/boxes/"+boxKey+"/fields/"+fieldKey;
"type": 'POST',
"dataType": "json",
"contentType": 'application/json; charset=utf-8',
"data": {value: yourValue}
花了一些时间来弄清楚参数的正确组合(Streak API文档在这部分中并不友好),但是我在代码中看到的内容对我来说是好的。它应该工作。
答案 1 :(得分:0)
以下是可用于编辑现有框中字段的功能。创建一个新框将采用相同的格式。
function editBox(boxKey, fieldKey, value) {
var url = 'https://www.streak.com/api/v1/boxes/' + boxKey + '/fields/' + fieldKey;
var params = {
headers: {Authorization: 'Basic ' + Utilities.base64Encode(STREAK_API_KEY + ":")},
method: "POST",
payload: JSON.stringify({
value: value
}),
contentType: 'application/json'
};
var field = UrlFetchApp.fetch(url,params );
return JSON.parse(field.getContentText());
}
答案 2 :(得分:0)
这是有效的:
function editBox() {
var boxKey = "xxx";
var value = "{value:Test}";
var fieldKey = "1001";
//{name:"Deal Size", key:"1001", type:"TEXT_INPUT", lastUpdatedTimestamp:1457089319053}
var url = 'https://www.streak.com/api/v1/boxes/' + boxKey + '/fields/' + fieldKey;
var params = {
headers: {Authorization: 'Basic ' + Utilities.base64Encode(streakApiKey)},
method: "POST",
payload: value,
contentType: 'application/json'
};
var result = UrlFetchApp.fetch(url,params );
var string = result.getContentText();
var Object = JSON.parse(string);
return Object;
}
function createBox() {
var pipelineKey = "xxx";
var name = "sample box name";
var url = 'https://www.streak.com/api/v1/pipelines/' + pipelineKey + '/boxes';
var RequestArguments = {
headers: {"Authorization": "Basic " + Utilities.base64Encode(streakApiKey)},
method: "PUT",
payload: {
name: name
}
};
var box = UrlFetchApp.fetch(url,RequestArguments);
var result = JSON.parse(box.getContentText());
return result;
}