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:
a.Click the line between the two nodes.
The line turns orange.
b.Press the Delete key.
The connection is removed.
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:
a.Double-click the inject node to open the Edit inject node dialog box.
b.Change the Payload text to 20 Enterprise, Aliso Viejo, then click Done.
5.Edit the tde rest node:
a.Double-click the tde rest node to open the Edit tde rest node dialog box.
b.For the Name field, enter geocode.
c.From the Endpoint drop-down list, select GET: geocode/{{country}}/{{address}}.
The country and address parameters are displayed in the Parameters section of the dialog box.
d.In the country parameter's value field, enter USA.
e.In the address parameter's value field, enter msg.payload.
This sets the address value used in this query to the payload sent from the inject node.
6.Enter the TDE credentials to use for the query in the tde rest node:
a.In the Edit tde rest node dialog box, click the edit icon to the right of the Config field.
If you do not already have a config defined, the Add new api-config config node dialog box opens.
b.Enter your TDE account information, including your Customer account name, the User name, and the Password for the account.
c.Click Test Connection.
If the connection test passes, click Add. If the connection fails and you are unable to resolve it, contact Verizon Connect customer support for assistance with your account details.
d.Click Done to close the Edit tde rest node dialog box.
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:
a.From the utility section of the nodes palette, click and drag the function node onto the central sheet and drop it between the tde rest and debug nodes.
When you hover the function node over the line between the tde rest and debug nodes, the line should become dotted. When you drop the function node over the dotted line, it is automatically connected to the other nodes.
b.Double-click the function node to open the Edit function node dialog box.
c.For the Name field, enter First Result.
d.In the Function text field, delete the default text and enter the following:
return msg.payload[0];
This function returns the first item in the msg.payload array passed to it from the tde rest geocode operation.
e.Click Done.
2.Add and edit the HTTP request node:
a.From the web section of the nodes palette, drag and drop the HTTP request node between the First Result function node and the debug node.
The HTTP request node should now be connected to the other two nodes.
b.Double-click the HTTP request node to open the Edit http request node dialog box.
c.In the URL field, enter the following address. Replace <your_api_key> with the API Key provided to you when you created your darksky.net/dev account.
https://api.darksky.net/forecast/<your_api_key>/{{{lat}}},{{{lon}}}
d.For the Name field, enter Weather.
e.Select the Use basic authentication? check box, and enter your darksky.net/dev Username and Password.
f.From the Return drop-down menu, select a parsed JSON object.
g.Click Done.
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.

Source Code

 
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"

    }

]