Is there an open API endpoint with current ImmyBot version?

With our RMM ImmyBot deployment script, I’ve enhanced it to allow for installing ImmyBot again if the current version is not equal to the installed version, as opposed to “only install if not installed.” To do this, I’ve implemented a version check that reads the filename header from the new perma-file endpoint, so if you pass in the -Uri of the latest version download URL, this function returns the version:

function Get-ImmyCurrentVersion {
    <#
    .SYNOPSIS
        Given the result of WebResponseObject with the ImmyBot download URL, determine the current version of ImmyBot from the file name.
    .DESCRIPTION
        Given the result of WebResponseObject with the ImmyBot download URL, determine the current version of ImmyBot from the file name.
    .PARAMETER WebResponse
        A WebResponseObject from running an Invoke-WebRequest on a file to download
    .EXAMPLE
        $version = Get-ImmyCurrentVersion -Uri 'https://subdomain.immy.bot/plugins/api/v1/1/installer/latest-download'
    #>
        [CmdletBinding()]
        param(
            [Parameter(Mandatory = $true)]
            [String]
            $Uri
        )

        # Manually invoke a web request
        $Request = [System.Net.WebRequest]::Create($Uri)
        $Request.AllowAutoRedirect = $true

        try {
            $Response = $Request.GetResponse()
        }
        catch {
            Write-Error 'Error: Web request failed.' -ErrorAction Stop
        }
        if ($Response.StatusCode -eq 'OK') {
            $AbsoluteUri = $Response.ResponseUri.AbsoluteUri
            $FileName = [System.IO.Path]::GetFileName($AbsoluteUri)
            if (-not $FileName) { Write-Error 'Error: Failed to resolve file name from URI.' -ErrorAction Stop }
            $FileName -match '^(\d+\.\d+\.\d+)\D+(\d+)' | Out-Null
            return $matches[1] + '.' + $matches[2]
        }
        return $null
}

This does work fine, and can be compared to the DisplayVersion registry key in the ImmyBot uninstall infomation on the system to determine if the versions match. However, is there a better place to call for the current version that might return a JSON format, that doesn’t require authentication, that I should use instead of this option? Just curious, haven’t been able to track down an alternate option. Thanks!

1 Like

This deployment/version check/uninstall script I wrote includes version checking similar to the post above, but improves it so that it doesn’t have to download the full installer, it just grabs the filename from the redirect and pulls the current version out of it. The full script is at:

The actual function, Get-ImmyCurrentVersion, is here, and it requires that you pass in the subdomain tenant name only (the * in *.immy.bot for your tenant), and it returns the current version from the agent install-redirector:

function Get-ImmyCurrentVersion {
  <#
  .SYNOPSIS
      Given the result of WebResponseObject with the ImmyBot teannt name, determine the current version of ImmyBot from the file name.
  .DESCRIPTION
      Given the result of WebResponseObject with the ImmyBot teannt name, determine the current version of ImmyBot from the file name.
  .EXAMPLE
      $version = Get-ImmyCurrentVersion -Tenant 'subdomain'
  #>
  [CmdletBinding()]
  param(
    [Parameter(Mandatory = $true)]
    [String] $Tenant
  )

  if ([string]::IsNullOrEmpty($Tenant)) {
    Write-Host "ERROR: No Tenant specified (required for cloud version check and download URL), quitting."
    return $false
  }

  $uri = "https://$Tenant.immy.bot/plugins/api/v1/1/installer/latest-download"
  Write-Verbose "URI for latest version information: $uri"

  try {
    # Manually invoke a web request
    $Request = [System.Net.WebRequest]::Create($uri)
    $Request.AllowAutoRedirect = $false
    $Response = $Request.GetResponse()
    Write-Verbose "Response Headers returned from version check:"
    Write-Verbose ($Response.Headers | fl * | Out-String)
    Write-Verbose "Location header value: $($Response.Headers['Location'])"
  }
  catch {
    Write-Error 'Error: Web request failed.' -ErrorAction Stop
  }
  if ($Response.StatusCode.value__ -eq '307') {
    $redirectUrl = $($Response.Headers['Location'])
    Write-Verbose "Redirect URL: $RedirectUrl"
    $FileName = [System.IO.Path]::GetFileName($redirectUrl)
    Write-Verbose "FileName: $FileName"
    if (-not $FileName) { Write-Error 'Error: Failed to resolve file name from URI.' -ErrorAction Stop }
    $FileName -match '^(\d+\.\d+\.\d+)\D+(\d+)' | Out-Null
    $version = $matches[1] + '.' + $matches[2]
    Write-Verbose "Version: $version"
    return $version
  }
  return $null
}

Feel free to use the function any way you’d like, and the script allows for arguments to install-if-not-installed/uninstall/install-only-if-outdated/version-check, documentation at the top.