Talking to TDE via the REST API
In the previous tutorial, we created a simple two-node flow that printed a Hello World text message to the debug tab. Now we expand that example to add the tde rest node, so that we can run a web query against the TDE API to geocode an address and country we provide and request the latitude and longitude coordinates of the address in return. We then send these coordinates to an external weather service to request the current weather conditions at the address.
You must have TDE authentication credentials to complete this tutorial. |
Part 1: Using the TDE REST Node to Geocode an Address
1. | From the telogis section of the nodes palette, click and drag the tde rest node onto the central sheet, and place it between the inject and debug nodes you created in the Creating a Basic Flow tutorial. |
2. | Disconnect the line between the inject and debug nodes: |
|
3. | Connect the inject node to the tde rest node, then connect the tde rest node to the debug node. |
4. | Change the text you are injecting: |
|
5. | Edit the tde rest node: |
|
6. | Enter the TDE credentials to use for the query in the tde rest node: |
|
7. | From the Flow Editor, click the Deploy button in the upper right corner of the screen. |
8. | Click the debug tab to open it. |
9. | From the central sheet, click the light blue circular button to the left of the inject node to launch the flow. The debug tab should now display an array that contains the geocode results, including the lat and lon coordinates. |
Part 2: Using Geocode Results to Get Weather Data
In the second part of this tutorial, we pass the latitude and longitude coordinates returned in Part 1 to an external API service that retrieves weather data for an address.
Because the debug node must always be the final step of a flow, we use a different node to pass the latitude and longitude details of our geocoding operation to an external weather service. The results from a geocoding operation are returned as an array, so we need to use only the first (highest probability) result from the array. To do this, we use a function node.
A free dev account with darksky.net is required to continue with this tutorial. |
1. | Add and edit the function node: |
|
2. | Add and edit the HTTP request node: |
|
3. | Double-click the debug node, change the Output option to complete msg object, then click Done. |
4. | From the Flow Editor, click the Deploy button in the upper right corner of the screen. |
5. | Click the debug tab to open it. |
6. | From the central sheet, click the light blue circular button to the left of the inject node to launch the flow. The debug tab should now display an array containing the results of the weather query. |
7. | Double-click the debug node and change the Output field to "message property". |
8. | In the msg. field, enter payload.currently.summary, then click Done. |
9. | Click the Deploy button, then launch the flow again. This time the debug tab only contains a summary of the current weather, pulled from the response received from forecast.io. |
The flow created in this tutorial is described by the JSON below. To successfully execute these flows, you must edit the tde rest node Config to add your own TDE credentials before you deploy.
To import a flow into the Editor, copy the code provided, click the upper right ≡ Menu button, then select "Import" > "Clipboard". Paste the code in the Import nodes window, then click Import.
Part 1 Code:
[
{
"id": "37801aae.162186",
"type": "inject",
"z": "e16fcf09.1cc0f",
"name": "inject",
"topic": "",
"payload": "20 Enterprise, Aliso Viejo",
"payloadType": "str",
"crontab": "",
"once": false,
"x": 150,
"y": 340,
"wires": [
[
"57939fa6.eac4d"
]
]
},
{
"id": "a13ff28f.6928a",
"type": "debug",
"z": "e16fcf09.1cc0f",
"name": "",
"active": true,
"console": "false",
"complete": "payload",
"x": 590,
"y": 340,
"wires": []
},
{
"id": "57939fa6.eac4d",
"type": "telogis-api",
"z": "e16fcf09.1cc0f",
"name": "geocode",
"config": "51b7ffc2.3c979",
"endpointQueryString": "endpoint=/geocode/{{country}}/{{address}}&method=get",
"parameters": [
{
"name": "country",
"value": "USA",
"in": "path"
},
{
"name": "address",
"value": "msg.payload",
"in": "path"
}
],
"x": 360,
"y": 340,
"wires": [
[
"a13ff28f.6928a"
]
]
},
{
"id": "51b7ffc2.3c979",
"type": "api-config",
"z": "e16fcf09.1cc0f",
"proxy": "",
"instance": "production",
"custominstance": "https://api.telogis.com/",
"labelValue": "production - acme123:main",
"useMessageCredentials": "false"
}
]
Part 2 Code:
[
{
"id": "1f69afa1.99494",
"type": "inject",
"z": "b693a4e4.d7c738",
"name": "inject",
"topic": "",
"payload": "20 Enterprise, Aliso Viejo",
"payloadType": "str",
"crontab": "",
"once": false,
"x": 110,
"y": 60,
"wires": [
[
"c719d3b0.76ade"
]
]
},
{
"id": "442225f2.52597c",
"type": "debug",
"z": "b693a4e4.d7c738",
"name": "",
"active": true,
"console": "false",
"complete": "payload.currently.summary",
"x": 990,
"y": 60,
"wires": []
},
{
"id": "c719d3b0.76ade",
"type": "telogis-api",
"z": "b693a4e4.d7c738",
"name": "geocode",
"config": "af2f74e.ea41c88",
"endpointQueryString": "endpoint=/geocode/{{country}}/{{address}}&method=get",
"parameters": [
{
"name": "country",
"value": "USA",
"in": "path"
},
{
"name": "address",
"value": "msg.payload",
"in": "path"
}
],
"x": 280,
"y": 60,
"wires": [
[
"e11c7928.6ab628"
]
]
},
{
"id": "e11c7928.6ab628",
"type": "function",
"z": "b693a4e4.d7c738",
"name": "First Result",
"func": "return msg.payload[0];",
"outputs": 1,
"noerr": 0,
"x": 490,
"y": 60,
"wires": [
[
"6448476e.631e98"
]
]
},
{
"id": "6448476e.631e98",
"type": "http request",
"z": "b693a4e4.d7c738",
"name": "Weather",
"method": "GET",
"ret": "obj",
"url": "https://api.darksky.net/forecast/c86b0fbbac42edf4850112cc77c0c890/{{{lat}}},{{{lon}}}",
"x": 720,
"y": 60,
"wires": [
[
"442225f2.52597c"
]
]
},
{
"id": "af2f74e.ea41c88",
"type": "api-config",
"z": "b693a4e4.d7c738",
"proxy": "",
"instance": "production",
"custominstance": "",
"labelValue": "production - acme123:main",
"useMessageCredentials": "false",
"credentialsCustomer": "acme123",
"credentialsUser": "main"
}
]