Start-UDRestApi on IIS


I have a dashboard that runs under IIS. Recently, I wanted to add a Rest API. My tests work fine locally but once on the IIS server, my Rest API doesn’t work and even my dashboard becomes inaccessible.

Are there any particular settings to be made on IIS?

Here is my IIS log :

Name      Port Running DashboardService                            
 ----      ---- ------- ----------------                            
Dashboard   80    True UniversalDashboard.Services.DashboardService
Start-UDRestApi : Failed to bind to address address already in use.
Au caractŠre C:\inetpub\wwwroot\dashboard.ps1:291 : 2
+     Start-UDRestApi -Name "Dashboard API" -Endpoint $ApiEndpoints -Ht ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Start-UDRestApi], IOException
    + FullyQualifiedErrorId : System.IO.IOException,UniversalDashboard.Cmdlets.StartRestApiCommand

Application is shutting down...

And my dashboard.ps1 :


$ApiEndpoints = Get-ChildItem (Join-Path $Cache:RootFolder 'api') -Recurse -File | ForEach-Object 
    & $_.FullName


$Dashboard = New-UDDashboard -Title "Dashboard" `
                             -EndpointInitialization $EndpointInit `
                             -LoginPage $LoginPage `
                             -Navigation $Navigation `
                             -Footer $Footer `
                             -Pages $Pages `
                             -Theme $Theme `
                             -AdminModeAuthorizationPolicy "Admin Mode"

    Start-UDDashboard -Name "Dashboard" -Dashboard $Dashboard -Endpoint $Endpoints -HttpsPort 443 -AdminMode -AutoReload -Certificate $Cert
    Start-UDRestApi -Name "Dashboard API" -Endpoint $ApiEndpoints -HttpsPort 10002 -Certificate $Cert -Wait

And a part of my Endpoint :

New-UDEndpoint -Url "/check-computercompliance" -Method "POST" -Endpoint {
        $Antivirus = $false,
        $NDESCertificate = $false

    ...SOME CODE...

    $Success = $IsLAPSEnabled + $IsMemberOfBitlockerADGroup + $IsMemberOfFirewallADGroup + $IsMemberOfMfaADGroup + !($ExceptionMessage.Count)

    $Response = @{
        Hostname = $Hostname
        Username = $Username
        IsAntivirusPresent = $Antivirus
        IsBitlockerKeyInAD = $IsBitlockerKeyInAD
        IsLAPSEnabled = $IsLAPSEnabled
        IsMemberOfBitlockerADGroup = $IsMemberOfBitlockerADGroup
        IsMemberOfFirewallADGroup = $IsMemberOfFirewallADGroup
        IsMemberOfMfaADGroup = $IsMemberOfMfaADGroup
        IsNDESCertificate = $NDESCertificate
        HtmlExceptionMessage = $HtmlExceptionMessage
        Success = $Success
    ConvertTo-Json -InputObject $Response

I tried Start-UDRestApi with or without the -Wait parameter, in http and https. I don’t see what’s stuck …

Thanks for your help :slight_smile:

You don’t need both Start-UDRestApi and Start-UDDashboard. Just pass all the endpoints (scheduled and API) to the -Endpoints parameter of Start-UDDashboard.

1 Like

Thank you for the quick reply. It works!

And I just saw that it was well marked in the documentation :roll_eyes:

I just have one problem with authentication. My dashboard authenticates via azure, is my rest API supposed to work on this same authentication?

When I identify myself with a user who works on the dashboard, on the rest API I have the following return “@ {error = Bad username or password}”

My invoke-restmethod :

$Authentication = @{
	Username = ""
	Password = "MySecretPassword"
$Token = Invoke-RestMethod -Uri "https://srv-xxx:443/api/login" -Method POST -Body $Authentication -ErrorAction Stop
$Response = Invoke-RestMethod -Uri "https://srv-xxx:443/api/check-computercompliance" -Method POST -Body $Body -Headers @{ Authorization = "Bearer $($Token.Token)" } -ErrorAction Stop

My authentication method on my dashboard :

$AzureParams = @{
    AppID    = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
    Instance = ''
    Domain   = ''
    TenantID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
$AuthenticationMethod = New-UDAuthenticationMethod @AzureParams