The process of installing nodes using the post method

Hello everyone, I would like to get ideas for a project.
I want to register a node with .tgz extension from my desktop application on the same local network to node-red on the other device.

Steps:

  1. Connecting to the local device via ssh
  2. this tgz file will be on my own computer and I will upload it to the other node-red device via ssh (The file path to be uploaded is ".node-red/nodes/xyz.tgz"
  3. I need to install the node at the path ".node-red/nodes/xyz.tgz" on this device

I found these in the Node-red documentation.

CURL Code;
curl -X POST http://localhost:1880/nodes -H "Content-Type: multipart/form-data" -F "tarball=@node-red-contrib-foo-1.0.3.tgz;type=application/ x-compressed-tar;filename=node-red-contrib-foo-1.0.3.tgz"

I want to ask 3 questions regarding this code?

  1. Is filename just the filename? Isn't the path to the file included?

  2. There is a note in the node-red document saying (Requires permission: nodes.write) for this curl code to work. How should I achieve this?

  3. Do I need tokens for this curl code to work? If so, how can I get it?

If you can think of any other ideas, I would appreciate it if you could share them. Generations after us can benefit from it :slight_smile:
Thank you from now

filename is just filename, the contents of the file is uploaded using the curl command.

By default the node red use has all permissions, you can basically ignore this.

If you setup a admin user/password in the settings.js, then yes, you'll need a token.

You can obtain a token using the /auth/token endpoint:

RED.util.evaluateNodeProperty(cfg.apiPassword, cfg.apiPasswordType,
                                          node, msg, (err, result) => {
              if (err) {
                node.status({fill:"red",shape:"dot",text:"Failed"});
                node.error("error occurred", {...msg, _err: err})
              } else {
                password = result;

                var data = {
                      "client_id":  "node-red-admin",
                      "grant_type": "password",
                      "scope":      "*",
                      "username":   username,
                      "password":   password
                }

                import('got').then( (module) => {
                  module.got.post( (cfg.hostUrl || msg.hostUrl) + "/auth/token", {
                    json: data
                  }).then( res => {
                    node.status({
                      fill:"blue",
                      shape:"dot",
                      text:"Sending flow"
                    });

                    var access_token = JSON.parse(res.body).access_token;

                    sendFlow({
                      "Authorization": "Bearer " + access_token
                    }, module.got);

                  }).catch((err) => {
                    node.status({fill:"red",shape:"dot",text:"Failed"});
                    node.error( "error occurred", { ...msg, _err: err });
                  });
                });
              }
            })

That code is taken from the SendFlow node from the introspection node package.

Full disclosure: I'm the author of that package.

İlginiz için teşekkür ederim. Peki curl komutuna örnek verebilir misiniz? Siz nasıl yapardınız mesala bu probleme karşı?

I take this to be:

Thank you for your attention. So can you give an example of the curl command? How would you do, for example, against this problem?

No I'm not going to create a curl command since I do this in Node-RED and secondly there is an example at the documentation for auth/token. :slight_smile:

You have created a road map. Thank you

1 Like

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