Skip to main content

Create session

Use Node-RED to create a session with FairCom Edge

Abstract

Tutorials to use Node-RED to create a session with FairCom Edge

Complete the tutorial requirements before this procedure.

  1. Drag an https request node into a flow.

  2. Double-click the request node to edit it.

    NodeEditor.png
    1. Select POST from the Method dropdown menu.

    2. Enter https://localhost:8443/api in the URL textbox.

    3. Check the Enable secure (SSL/TLS) connection checkbox.

    4. Create a new TLS Configuration.

      • Uncheck the Verify server certificate.

      • Create certificates for your FairCom Edge server and configure them.

    5. Click Done to finish configuring the node and to close the node editor.

  3. Drag a json node into the flow.

  4. 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.

  5. Drag an inject node into the flow.

  6. Connect the output of the inject flow to the input of the https request node.

  7. Double-click the inject node to edit it.

    1. Enter createSession in the Name textbox.

    2. Enter {} JSON in the msg.payload textbox.

    3. Click ... to open the JSON editor.

    4. Paste the following JSON in the JSON editor textbox:

      {
          "api": "admin",
          "action": "createSession",
          "params": {
              "username": "ADMIN",
              "password": "ADMIN"
          }
      }
      
    5. Click Done to close the JSON editor.

    6. Click Done so that now the inject node will send a JSON object that requests a new session from the FairCom Edge server.

      Note

      The response will include an authtoken.

  8. Drag a function node into the flow.

    Note

    We will configure this node to save the authtoken for use in other nodes.

  9. Connect the output of the json node to the input of the function node.

  10. Double-click the function node to edit it.

    1. 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;
    2. Enter Store Auth Token in the Name textbox.

    3. Click Done 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".

  11. Click Deploy to save the flow and make it ready for use.

  12. 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.