2016-05-06 4 views
0

Trelloのリストにカードが置かれているとき、Harvestで請求書を生成するのが本質的です。私はZapierを試しましたが、インボイスの機能は組み込まれていません。POST GETまたはZapierトリガーPOSTアクションへ

私はこれを自分で開発する必要があります。 TrelloはJavascriptやPythonのアクションを持っているので、私はその2つの言語に限定されています。

ZAPIER: Trello Trigger > Javascript or Python code 

は、私は私が含む基本的なログイン認証を使用して最低限 PythonやJavaScriptでこれを投稿することができますどのように

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" } }

に送信する必要がJSONリクエストを持っています論理?コードのサンプルビットが役に立ちます。

UPDATE: 私はこのコードを追加したが、それはポストマン外で働くことを得るように見えることはできません

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);
あなたが制限されていないので、

答えて

0

Trelloは、本格的なREST APIを持っていますあなたが使用しているZapによって設定されている制限でない限り、PythonまたはJavaScriptだけです。これは、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) 
+0

私は収穫で実行するようにコードを変更したが、それは文句を言わない郵便配達の外で働きます。 –