我本质上想要做的是当一张卡片放在 Trello 的列表中时,在 Harvest 中生成一张发票。我试过 Zapier,但它没有内置发票功能。
我需要自己开发这个。Trello 有一个 Javascript 或 Python 操作,所以我仅限于这两种语言。
ZAPIER: Trello Trigger > Javascript or Python code
我有需要发送到的 JSON 请求
https://[site].harvestapp.com/invoices
Authorization: Basic amNtMjU4MkBnbWFpbC5jb206YTEwMDUw**NB
Content-Type: application/javascript
Accept: application/json
{
"invoice": {
"due_at_human_format": "NET 10",
"client_id": 3849315,
"currency" : "United States Dollar - USD",
"issued_at": "2015-04-22",
"subject": "Your invoice subject goes here",
"notes": "Some notes go here",
"number": "303197",
"kind": "project",
"projects_to_invoice": "120353",
"import_hours": "yes",
"import_expense": "yes",
"period_start": "2015-03-01",
"period_end": "2016-03-31",
"expense_period_start": "2015-03-31",
"expense_period_end": "2016-03-31"
}
}
如何使用包括逻辑的基本登录身份验证在准系统python 或 JavaScript 中发布此内容?一些示例代码会有所帮助。
更新:我已经添加了这段代码,但似乎无法让它在邮递员之外工作
var data = JSON.stringify({
"invoice": {
"due_at_human_format": "NET 10",
"client_id": 3849315,
"currency": "United States Dollar - USD",
"issued_at": "2015-04-22",
"subject": "Your invoice subject goes here",
"notes": "Some notes go here",
"number": "303197",
"kind": "project",
"projects_to_invoice": "120353",
"import_hours": "yes",
"import_expense": "yes",
"period_start": "2015-03-01",
"period_end": "2016-03-31",
"expense_period_start": "2015-03-31",
"expense_period_end": "2016-03-31"
}
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://[url].harvestapp.com/invoices");
xhr.setRequestHeader("authorization", "Basic amNtMjU4MkBnbWFpbC***TEwMDUwMTNB");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("postman-token", "2c652344-1be5-8969-adf3-a7ca9ee7179f");
xhr.send(data);