Getting "Invoke-RestMethod : The remote server returned an error: (404) Not Found." when trying to call an end-point

Hello,
Newb here, I just discovered Powershell Universal a few hours ago and I’m intrigued. I installed the software on my Windows 10 and testing here. I created a very simple script “get-process” just to test to see if I got any about from the PowerShell console.

I can run the script in the portal without any issues. But when i run it “remotely” local PowerShell console i get the following error message:

Invoke-RestMethod “http://localhost:5000/test
Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At line:1 char:1

  • Invoke-RestMethod “http://localhost:5000/test
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    
    

I followed the doc step by step. I’ve disabled the local firewall temporarily to get that out of the equation so i dont know what I’m doing wrong.

I appreciate your time/assistance and advise in advance.

-J

Hi,

Could you please send the content from endpoints.ps1, it’s usually located in
cC\ProgramData\UniversalAutomation\Repository.universal

Hello,
Thanks for your response. I dont have that folder, the installation is on the “c:\Program Files (x86)\Universal”. I also did a search on the entire disk and nothing.

@jchera You can view the file suggested by @BuggeX in the admin console by navigating to Settings \ Configurations and then clicking the Repository \ .universal \ endpoints.ps1 file.

Gotcha, here you go, thank you.

New-PSUEndpoint -Url “/service” -Description “Get all services.” -Method @(‘GET’) -Endpoint {
Get-Service | Select-Object -Property Name,DisplayName,@{Name=“Status”;e={$_.Status.ToString()}}
}
New-PSUEndpoint -Url “/service/:name” -Description "Delete a service by name. " -Method @(‘DELETE’) -Endpoint {
param($Name)

Remove-Service -Name $Name -Confirm:$false
}
New-PSUEndpoint -Url “/service” -Description "Create a new service. " -Method @(‘POST’) -Endpoint {
param(
[Parameter(Mandatory)]
$Name,
[Parameter(Mandatory)]
$Path
)

New-Service -Name $Name -BinaryPathName $Path

# Invoke-RestMethod http://localhost:5000/service -Method POST -Body @{ Name = “myService”; Path = ‘myService.exe’ }

}
New-PSUEndpoint -Url “/service/:name” -Description “Get a service by name.” -Method @(‘GET’) -Endpoint {
param($Name)

Get-Service -Name $Name | Select-Object -Property Name,DisplayName,@{Name=“Status”;e={$_.Status.ToString()}}
}
New-PSUEndpoint -Url “/service/:name/status” -Description "Control the state of a service. " -Method @(‘PUT’) -Endpoint {
param($Name)

$Service = Get-Service -Name $Name
if ($Service.Status -eq ‘Stopped’)
{
Start-Service -Name $Name
}
else
{
Stop-Service -Name $Name
}
}
New-PSUEndpoint -Url “/hello-world” -Method @(‘GET’) -Endpoint {

# Enter your script to process requests.

get-computerinfo
} -Authentication

Not sure if you changed endpoints after you created this post, but as far as I can tell, there
is no endpoint configured for test, so ofc the server would return 404.

I also don’t see an endpoint that has get-process, so i believe you mistook Automation/Scripts with APIs/Endpoints?