Create session
Use Node-RED to create a session with FairCom Edge
Tutorials to use Node-RED to create a session with FairCom Edge
Complete the tutorial requirements before this procedure.
Drag an
https
request node into a flow.Double-click the request node to edit it.
Select POST from the Method dropdown menu.
Enter
https://localhost:8443/api
in the URL textbox.Check the Enable secure (SSL/TLS) connection checkbox.
Create a new TLS Configuration.
Uncheck the Verify server certificate.
Create certificates for your FairCom Edge server and configure them.
Click
to finish configuring the node and to close the node editor.
Drag a json node into the flow.
Connect the output of the
https
request node to the input of the json node.Note
The FairCom Edge server returns info in JSON format. The json node will translate the response into a native JSON object.
Drag an inject node into the flow.
Connect the output of the inject flow to the input of the
https
request node.Double-click the inject node to edit it.
Enter
createSession
in the Name textbox.Enter
{} JSON
in the msg.payload textbox.Click
to open the JSON editor.Paste the following JSON in the JSON editor textbox:
{ "api": "admin", "action": "createSession", "params": { "username": "ADMIN", "password": "ADMIN" } }
Click
to close the JSON editor.Click FairCom Edge server.
so that now the inject node will send a JSON object that requests a new session from theNote
The response will include an authtoken.
Drag a function node into the flow.
Note
We will configure this node to save the authtoken for use in other nodes.
Connect the output of the json node to the input of the function node.
Double-click the function node to edit it.
Paste the following code in the On Message code editor textbox:
var authToken = msg.payload.result.authToken; node.status("Got token:"+authToken); flow.set("tutorial_authToken", authToken); return msg;
Enter
Store Auth Token
in the Name textbox.Click
to finish configuring the node and to close the node editor.Note
This node will parse the JSON response object and grab the returned authtoken then store it in a flow variable called
"tutorial_authToken"
.
Click
to save the flow and make it ready for use.Click the corresponding createSession node button to send the request for a new session to the FairCom Edge server.
Note
The authtoken for this session will be stored in a flow variable. You can inspect the flow variable via the Context Data tab or add a debug node connected to the output of the json node to see it.