node red - I try to export all existing flows from a remote NodeRed server with admin credentials, but get Error "Unaut

admin2025-04-27  3

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
Share Improve this question edited Jan 11 at 14:50 Mdarende asked Jan 11 at 14:45 MdarendeMdarende 7951 gold badge12 silver badges30 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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.

转载请注明原文地址:http://anycun.com/QandA/1745708069a91114.html