Help with Admin API Methods

First off thank you for taking the time to help me. I am currently lost with what I need to do to import my flows through the command line. I have read through the Admin API Methods here and this website here on examples.

Using the below curl in the command line

curl -X GET http://localhost:1880/auth/login

gives me the output

{}

From what I understand with this is that I do not have active authentication on so I should not have to use any authentication credentials when I use POST.

Now going back to the examples website anytime I follow their "replace all flows from a file" I get a error below

{"code":"unexpected_error","message":"config.forEach is not a function"}curl: (6) Could not resolve host: application

The file has the following information in it.

[{"id":"bed4fb91.f40858","type":"tab","label":"Sheet 1","disabled":false,"info":""},{"id":"3bcc44ce.14cafc","type":"inject","z":"bed4fb91.f40858","name":"Trigger","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":140,"wires":[[]]}]

And I am using this curl code on the command line

curl -X POST http://localhost:1880/flows -H 'content-type: application/json' -d @flows

What am I doing wrong? Also my end goal is to take an exported flow file and import the flow over command line so if there is a better way I can do this please let me know.

Have you contacted the people that provided the example and asked them about it?
When was their example written?
What version of Node-red were they using and what version are you using?

Why do you want to import the flow via the command line?

I have not contacted the people who provided the examples and they do not state what version of node-red they are using.

I want to use the command line so I can automate the node-red installation process on a new machine using a batch file.

In that case just place the flows file you want in the .node-red folder.

Thanks Colin for that information and this option seems to work well for me, this brings me to another question. I found the settings.js file under

%userprofile%\AppData\Roaming\npm\node_modules\node-red\ 

and noticed there was a section with the below code.

// The file containing the flows. If not set, it defaults to flows_<hostname>.json
//flowFile: 'flows.json',

I uncommented it like so

// The file containing the flows. If not set, it defaults to flows_<hostname>.json
flowFile: 'flows.json',

and started node-red but it did not load my flows.json file under

%userprofile%\.node-red

am I missing something or modifying the wrong settings.js file?

Thanks again for everyone's help I do appreciate it.

Look in the node red startup log and it will tell you which settings file it is using. Normally it is in the same directory as the flows file.

Colin,

Thanks again and this was the issue, I took a look at the logs from pm2 and it was using the settings from the same directory as the flows file.

For anyone following along or anyone who finds this in the future I ended up just uncommenting the below code in the settings.js file in the same directory as the flows (run from cmd line cd %userprofile%\.node-red)

// The file containing the flows. If not set, it defaults to flows_<hostname>.json
flowFile: 'flows.json',

The reason I did it this way was because I have pm2 running my node-red instance and just creating a generic flows.json makes it easy to copy all the flows over to the new pc.

1 Like

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