Node-REDでSalesforceのデータをTreasure Dataに送る方法
はじめに
行ったこと
本記事では、Node-REDを用いてSalesforceに入っている情報をTreasure Dataのデータベースに送る方法について述べます。今回は例として、Salesforceに入っているアカウント(取引先)情報のうち、アカウント名とアカウントIDをTreasure Dataに送りました。
環境
Mac OSX Yosemite Version 10.10.5
Node-RED Version v0.11.0
Node.js Version v0.12.7
完成形
ポイント
1. TDノードの認証には、Write-Only API keysを使う
TDノードの認証を行うと、AccountとWritekeyを求められます。
このWritekeyを取得する必要があるので、右上からMy profileを選びます。
右側に、API Keysを取得するためのパスワードを入力するところがあるので入力します。
API Keysが表示されるので、Write-Only API keysをコピーし、TDノードに入力します。
2. Splitterでレコードを分ける
これをSplitterノードでrecordsをキーに設定して分けると、以下のようなレコードに別れます。
3. ネストを取り除く
TDノードにはネストしたデータは入れられないので、ネストしているattributesキーを取り除きます。
functionノードに、以下を入力することでattributesキーを取除くことができます。
delete msg.payload['attributes'];
return msg;
このオブジェクトをTreasure Dataに送ると、Treasure DataのTableにデータが入ります。
コード
force-TD
[{
"id": "a16083e8.2530c",
"type": "force",
"username": "Username",
"loginurl": "https://login.salesforce.com",
"logintype": "Username-Password"
}, {
"id": "d2c6ac93.938608",
"type": "td",
"account": "Username"
}, {
"id": "2bca0383.da718c",
"type": "td out",
"td": "d2c6ac93.938608",
"name": "",
"database": "db_test",
"table": "table1",
"x": 703,
"y": 206,
"z": "b5890722.4a76f8",
"wires": []
}, {
"id": "7d9f5468.e69e94",
"type": "inject",
"name": "",
"topic": "",
"payload": "select ID,Name from Account",
"payloadType": "string",
"repeat": "",
"crontab": "",
"once": false,
"x": 122,
"y": 94,
"z": "b5890722.4a76f8",
"wires": [
["d63a4417.6ea9f"]
]
}, {
"id": "d63a4417.6ea9f",
"type": "force in",
"force": "a16083e8.2530c",
"operation": "query",
"sobject": "",
"extname": "",
"name": "",
"x": 215,
"y": 206,
"z": "b5890722.4a76f8",
"wires": [
["4f9d4190.0da758"]
]
}, {
"id": "dcd71ed2.c1acf8",
"type": "function",
"name": "Delete \"attributes\"",
"func": "delete msg.payload['attributes'];\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 468,
"y": 193,
"z": "b5890722.4a76f8",
"wires": [
["2bca0383.da718c"]
]
}, {
"id": "4f9d4190.0da758",
"type": "splitter",
"name": "",
"property": "payload.records",
"x": 353,
"y": 79,
"z": "b5890722.4a76f8",
"wires": [
["dcd71ed2.c1acf8"]
]
}]
[{
"id": "a16083e8.2530c",
"type": "force",
"username": "Username",
"loginurl": "https://login.salesforce.com",
"logintype": "Username-Password"
}, {
"id": "d2c6ac93.938608",
"type": "td",
"account": "Username"
}, {
"id": "2bca0383.da718c",
"type": "td out",
"td": "d2c6ac93.938608",
"name": "",
"database": "db_test",
"table": "table1",
"x": 703,
"y": 206,
"z": "b5890722.4a76f8",
"wires": []
}, {
"id": "7d9f5468.e69e94",
"type": "inject",
"name": "",
"topic": "",
"payload": "select ID,Name from Account",
"payloadType": "string",
"repeat": "",
"crontab": "",
"once": false,
"x": 122,
"y": 94,
"z": "b5890722.4a76f8",
"wires": [
["d63a4417.6ea9f"]
]
}, {
"id": "d63a4417.6ea9f",
"type": "force in",
"force": "a16083e8.2530c",
"operation": "query",
"sobject": "",
"extname": "",
"name": "",
"x": 215,
"y": 206,
"z": "b5890722.4a76f8",
"wires": [
["4f9d4190.0da758"]
]
}, {
"id": "dcd71ed2.c1acf8",
"type": "function",
"name": "Delete \"attributes\"",
"func": "delete msg.payload['attributes'];\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 468,
"y": 193,
"z": "b5890722.4a76f8",
"wires": [
["2bca0383.da718c"]
]
}, {
"id": "4f9d4190.0da758",
"type": "splitter",
"name": "",
"property": "payload.records",
"x": 353,
"y": 79,
"z": "b5890722.4a76f8",
"wires": [
["dcd71ed2.c1acf8"]
]
}]
Author And Source
この問題について(Node-REDでSalesforceのデータをTreasure Dataに送る方法), 我々は、より多くの情報をここで見つけました https://qiita.com/junkonakajima/items/03ac53addcfa6b7931fb著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .