Axios API Request

I am new to creating custom nodes and I am attempting to use axios with the node. The API get request is working fine from a JS file but with a Node-Red flow I receive a "Node not deployed" message. May be something very basic on my first attempt to deploy a created/custom node that I am missing. Does anything stand out below as an error in the code of the JS file? I followed basic steps (creation of HTML and JS files, creation of the package.json file via npm init, and npm install to deploy the node. The node shows up within the pallet but receive the error provided on invoke.

module.exports = function(RED) {
    function LowerCaseNode(config) {
        RED.nodes.createNode(this,config);
        axios.get("http://10.0.0.10/getxml?location=/Status/SystemUnit/State", {
        headers: {Authorization: "Basic XXXXX"}
        }).then((response) => {
            msg.payload = response.data
        }), (error) => {
            msg.payload = error
        }

    }
}

The "Node not deployed" error message can have several reasons:

  • you didn't press "Deploy" after adding the node to the flow canvas
  • the node is disabled
  • the node is on a disabled flow tab

But without seeing your actual flow, it's hard to say.

If the node shows up in the palette, then the first step worked fine.

But looking at your node's code, it doesn't send any message at all. You'd have to use node.send(msg) for that.
If you want to react on incoming messages, you have to register an event handler using node.on('input', ...)

Here are the details: https://nodered.org/docs/creating-nodes/node-js#sending-messages

Hint: If you want to share flows or code snippets, please enclose them in ``` for proper formatting.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.