Hello,
I hope someone can help me. I’m trying to restart a server in the home network using a POST request. I have a Powershell script for this that works perfectly…
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$session.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"
Invoke-WebRequest -UseBasicParsing -Uri "http://192.168.0.90/api/maintenance/reboot" `
-Method "POST" `
-WebSession $session `
-Headers @{
"Accept"="*/*"
"authorization"="Basic YWRtaW46UmVnaW5hMjAyMiE="
"x-requested-with"="XMLHttpRequest"
} `
-ContentType "multipart/form-data; boundary=----WebKitFormBoundary97o3LZvX3ePgz4c4" `
-Body ([System.Text.Encoding]::UTF8.GetBytes("------WebKitFormBoundary97o3LZvX3ePgz4c4$([char]13)$([char]10)Content-Disposition: form-data; name=`"data`"$([char]13)$([char]10)$([char]13)$([char]10){`"reboot`":true}$([char]13)$([char]10)------WebKitFormBoundary97o3LZvX3ePgz4c4--$([char]13)$([char]10)"))
After racking my brain for a few days, I’ve now gotten to this point and added the following code to my configuration.yaml…
rest_command:
reboot_device:
url: "http://192.168.0.90/api/maintenance/reboot"
method: "POST"
headers:
Accept: "*/*"
authorization: "Basic YWRtaW46UmVnaW5hMjAyMiE="
x-requested-with: "XMLHttpRequest"
Content-Type: "multipart/form-data; boundary=----WebKitFormBoundary97o3LZvX3ePgz4c4"
User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"
payload: "------WebKitFormBoundary97o3LZvX3ePgz4c4\r\nContent-Disposition: form-data; name=\"data\"\r\n\r\n{\"reboot\":true}\r\n------WebKitFormBoundary97o3LZvX3ePgz4c4--\r\n"
I restarted HA → DEV TOOLS → Action/Service and tried to run it, without success.
I am getting a client error.
regards
Claus