0

我本质上想要做的是当一张卡片放在 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);

4

1 回答 1

0

Trello 有一个完整的 REST API,因此您不仅限于 Python 或 JavaScript,除非这是您正在使用的 Zap 设置的限制——这是可能的,因为 Zapier 主要构建在 Django 上。

话虽如此,很容易以任何一种语言触发 POST 请求。这是一个适合您的 JavaScript 示例,尽管您必须对其进行调整以满足您的特定需求。

var request = new XMLHttpRequest();
var url = 'https://[site].harvestapp.com/invoices'; // or whatever your url actually is
var headers = {
    Authorization: 'amNtMjU4MkBnbWFpbC5jb206YTEwMDUw**NB',
    Content-Type: 'application/javascript',
    Accept: 'application/json'
};
var params = { // your JSON encoded data };

request.open( 'POST', url, true );
request.setRequestHeader( headers );
request.send( params );

在 Python 中,它看起来像这样:

import requests
url = 'https://[site].harvestapp.com/invoices'
request.headers = {
    'Authorization': 'amNtMjU4MkBnbWFpbC5jb206YTEwMDUw**NB',
    'Content-Type': 'application/javascript',
    'Accept': 'application/json'
}
data = {} # put your data there instead of an empty dictionary
request.post( url, data )
于 2016-05-06T18:41:46.440 回答