REST API Issue

REST API Issue

I am currently working through creating a PowerShell Module leveraging the PasswordManager Pro REST API.  However, I am running into issues when trying to delete resources without any accounts associated with them.  This is due to the REST API Call  https://[my url]/restapi/json/v1/resources?AUTHTOKEN=[my token] not returning the ResourceID attribute when the row count is 0.  Below is the function to return a ResourceID including how to call it from within PowerShell.  Currently it will return a ResourceID ONLY when 1 or more accounts exist within the resource.  Any help you can provide in identifying how to making this return a ResourceID when no Accounts exist for a resource would be greatly appreciated.

Scott Clark

Usage:
[string]$ApiToken = '[removed]'
[string]$ServerName = 'pmp.[removed].com'
[string]$ResourceName = 'computername'

Get-PMPResourceID -ResourceName $ResourceName -ApiToken $ApiToken -ServerName $ServerName

Function:

Function Get-PMPResourceID 
{
 
  [cmdletbinding()]
  
  param (
      [Parameter(Mandatory,HelpMessage='Enter a Resource Name')]
      [string]$ResourceName,

      [string]$AccountName='',

      [Parameter(Mandatory,HelpMessage='Enter the API Token for this host')]
      [string]$ApiToken,

      [Parameter(Mandatory,HelpMessage='Enter the name of the PasswordManager Pro Server')]
      [string]$ServerName
  )

  try 
  {
    if($AccountName -eq '')
    {
      $Uri = (' https://{0}/restapi/json/v1/resources?AUTHTOKEN={1}' -f $ServerName,$ApiToken) 
    }
    else
    {
      $Uri = (' https://{0}/restapi/json/v1/resources/resourcename/{1}/accounts/accountname/{2}?AUTHTOKEN={3}' -f $ServerName,$ResourceName,$AccountName,$ApiToken) 
    }

    $Result = Invoke-RestMethod -uri $Uri -Method Get | Select-Object -ExpandProperty operation
  
    if ($Result.result.status -eq 'Success') 
    {
      (($Result.Details | Where-Object{$_.'RESOURCE NAME' -eq $ResourceName}).'RESOURCE ID', $Result.Details.RESOURCEID -ne $null)[0]
    }
    else 
    {
      throw $Result.result.message
    }
  }
  catch 
  {
    throw $Error[0]
  }
        
}

                New to ADManager Plus?

                  New to ADSelfService Plus?