How to export flows of a nodered server from remote server with powershell?

dargento
Mon, 13 Jan 2025 13:52:52 +0000
General

Hello, We have several nodered servers in our company and I want export the flows from each server periodically for some evaluation. When the server has no authentication (just on test server) I can directly get flows with https://mynoderedserver:1880/flows. But when the servers have authentication I get "unauthorized". Normaly I can login to the servers and export the flows manually. But I want to be able to do that with a powershell script. I have also tried some scripts with credentials but each time I get the flows.json file just with the comment "unauthorized".

When I enter NodeRed webpage with my credentials I see that as user I am defined as admin. Why can I not download the flows.json file? How should I proceed?

My Code is:

# Define the Node-RED server URL
$nodeRedUrl = "https://myserver:1881"

$apiEndpoint = "/flows"

# Define the credentials
$username = "myusername"
$password = "mypassword"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)

# Make an HTTP GET request with credentials to retrieve the flows
$response = Invoke-WebRequest -Uri ($nodeRedServerUrl + $apiEndpoint) -Method Get -Credential $credential

# Save the response content to a JSON file in C:\temp
$response.Content | Set-Content -Path "C:\temp\flows.json"

6 posts - 5 participants

Read full topic