We have a nodered server in our company. When I enter the nodered servers web page over my PC's browser I just click on a login button and not more asked for credentials, and I am in. I see my user "abc" as admin. I can export from the nodered menue all the flows as one json file without problem.
Now I want to do this export remotely via command line. But when I have tried following commandline code with my same admin credentials (as I log in to Windows on my PC) , I get just text "Unauthorized" in the exported json file. In the setting file settings.js of the nodered server I can see that the nodered has authentication type "credentials". What is missing? Why can I export manually, and why not remotely via command line?
C:\>curl -u myuser:mypassword https://myserver:1881/flows -o C:\temp\nodered_flows.json
We have a nodered server in our company. When I enter the nodered servers web page over my PC's browser I just click on a login button and not more asked for credentials, and I am in. I see my user "abc" as admin. I can export from the nodered menue all the flows as one json file without problem.
Now I want to do this export remotely via command line. But when I have tried following commandline code with my same admin credentials (as I log in to Windows on my PC) , I get just text "Unauthorized" in the exported json file. In the setting file settings.js of the nodered server I can see that the nodered has authentication type "credentials". What is missing? Why can I export manually, and why not remotely via command line?
C:\>curl -u myuser:mypassword https://myserver:1881/flows -o C:\temp\nodered_flows.json
The admin API does not use the username and password, it uses a Bearer token as described in the docs here:
https://nodered.org/docs/api/admin/oauth
You need to generate a token from the username/password as follows:
$ curl http://localhost:1880/auth/token --data 'client_id=node-red-admin&grant_type=password&scope=*&username=admin&password=password'
{
"access_token": "A_SECRET_TOKEN",
"expires_in":604800,
"token_type": "Bearer"
}
Replacing admin
and password
with the right values
You can then call the API with
$ curl -H "Authorization: Bearer A_SECRET_TOKEN" http://localhost:1880/flows -o flows.json
Be aware that even exporting all the flows like this, the API will NEVER return any credentials linked to the flow.