[英]API GET or Zapier trigger to POST action
What i am essentially trying to do is generate an invoice in Harvest when a card is placed in a list in Trello. 我本质上想做的就是将卡放在Trello的列表中时在Harvest中生成发票。 I have tried Zapier, but there is no invoice functionality built in to it.
我已经尝试过Zapier,但是没有内置的发票功能。
I will need to develop this myself. 我将需要自己开发。 Trello has a Javascript or Python action so i am limited to those two languages.
Trello具有Javascript或Python操作,因此我仅限于这两种语言。
ZAPIER: Trello Trigger > Javascript or Python code
I have the JSON request that i need to be sent to 我有需要发送到的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" } }
How can i post this in bare-bones python or JavaScript using basic login authentication including logic? 我怎样才能张贴此在裸机 Python或使用JavaScript基本的登录认证,包括逻辑? A sample bit of code would be helpful.
样本代码会有所帮助。
UPDATE: I have added this code, but cannot seem to get it to work outside Postman 更新:我已添加此代码,但似乎无法使它在邮递员之外工作
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);
Trello has a full fledged REST API, so you're not limited to just Python or JavaScript unless that's a limitation set by the Zap that you're using -- which is possible as Zapier is built mostly on Django. Trello具有完整的REST API,因此您不仅限于Python或JavaScript,除非这是您使用的Zap设置的限制-这可能是因为Zapier主要基于Django构建。
With that being said, it's very easy to just fire off a POST request in either language. 话虽如此,仅用两种语言触发POST请求都是非常容易的。 Here's a JavaScript example for you, though you'll have to adapt this to meet your specific needs.
这是一个适合您的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 );
In Python it would look something like this: 在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 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.