我已经尝试了所有我能想到的组合来完成这项工作。我需要将什么作为POST
字段发送到 New Basecamp API 以使其接受我的 POST 数据?
我的代码是:
function getFilterBy() {
var url = "https://basecamp.com/****/api/v1/projects/*****.json";
var payload = {"name" : "myapp", "description" : "no desc mls"};
var opt = {
"contentType" : "application/json",
"method" : "POST",
"headers":{ "User-Agent": "myapp (user@somewhere.com)",
"Authorization" :"Basic " + Utilities.base64Encode("user" + ":" + "pass")},
"validateHttpsCertificates" :false,
"muteHttpExceptions" : true,
"payload" : payload
};
var response = UrlFetchApp.fetch(url, opt);
var text = response.getContentText();
Logger.log(text);
}
我的错误是:
lexical error: invalid char in json text.
description=no+desc+mls&name=Ho
(right here) ------^
我试过了Utilities.jsonStringify
,但没有运气。我知道这是一个菜鸟错误,但我就是想不通。如果有一个地方你知道我也可以从哪里获得这些信息,那将是惊人的。
谢谢!
更新 1
function getFilterBy() {
var url = "https://basecamp.com/****/api/v1/projects/****.json";
var payload = {name : 'myApp Change'};
var opt = {
"contentType" : "application/json",
"method" : "POST",
"headers":{ "User-Agent": "myApp (user@ex.com)",
"Authorization" :"Basic " + Utilities.base64Encode("user" + ":" + "pass")},
"validateHttpsCertificates" :false,
"muteHttpExceptions" : true,
"payload" : Utilities.jsonStringify(payload)
};
var response = UrlFetchApp.fetch(url, opt);
var text = response.getContentText();
Logger.log(text);
}
产量错误:
<body>
<div class="dialog">
<div class="innercol">
<h1>Hmm, that isn’t right</h1>
<h2>You may have typed the URL incorrectly.</h2>
<p>Check to make sure you’ve got the spelling, capitalization, etc. exactly right.</p>
</div>
</div>
<p id="back" class="back">
<a href="javascript:window.history.back();">← Back to previous page</a>
</p>
<script type="text/javascript">
if (window.history.length <= 1) document.getElementById("back").style.display = "none";
</script>
</body>