This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I give up. How is this done?! API Filtering via Invoke-RestMethod

I am not the DBA.  I'm not even sure if I'm as good as I think I am after tackling this task.

I am a web user of the AssetManager web service.  I can query this using point and click -

Branching out - I requested access to same - using the API.

I wrote a bit of powershell code to connect to the DB/Table 'amPorfolio' - and can query assets and get back meaningful responses.

My sticking point is filtering on the server side in the API.   How does one compose a URI containing a compound filter?

The filter that works for me is "&filter=(attribute = 'value')"

How I use it:

$AMSERVER = 'http://MYSERVER:8080/'
$AMDBTABLE = 'AssetManagerWebService/rs/db/amPortFolio/'
$AMFILTER = "&filter=(DeviceType = 'Server')"

$fin = Invoke-RestMethod "$($AMSERVER)$($AMDBTABLE)$($AMFIELDS)$($AMFILTER)" `
-SessionVariable websession `
-Credential $User_cred `
-Headers @{"SOAPAction" = "Retrieve"; "Authorization" = "Basic "}

... and I am looking for something similar to the example below, where the PowerShell URI filter can include "IS this or that value"
... and to extend that - a method for leveraging something like

"&filter=(field0 = 'this' -and/or (field1 = 'this -and/or 'that')"
"&filter=startswith/endswith(attribute , 'value')" or
"&filter=contains(deviceName , 'partialna')"

is such a capability present?  Is there an accessible document available that fleshes that API out a bit more? 
I'm just not tripping over the right syntax if its in the API  without some sort of guidance.

Function testReadFromAM() {
	var table = "amAsset";
	var fields = "lAstId,Label,lModelId";
	var where = "Where AssetTag LIKE 'CPU00001%' AND lTenantId = 12345";
example above from: Call Asset Manager 9.40 RESTful API from Service Manager 9.40 - Service Manager / Service Center User Discussions - SMA-Service Manager Suite (microfocus.com)



  • 0

    I assume no nibbles on this post - means powershells' invoke-restmethod can't be used to build a questionably complex query in the current version API.

    Given that - my query ends up being - select only the fields I want, & startswith(attribute,value).  Once I return the mass data from the host using pagination, I filter on the client side to do the complex filtering 'except this, or that,or that. Unamused

    ------------------------------------------------------------------------------


    $qtype='startswith' #options are startswith,contains,endswith
    $user = login name, or portion thereof

    $Uri = "https://<myserverFQDN>:60080/aternity.odata/latest/DEVICE_INVENTORY?`$select=USERNAME,TIME_LAST_REPORTING,DEVICE_NAME,DEVICE_IP_ADDRESS,BUSINESS_LOCATION,WIFI_SSID&`$count=true&`$filter=$($qtype)(USERNAME,'$USER')
    "
    $response = (Invoke-RestMethod -Uri $uri -Credential $apiCredential )
    $response.value
    if($Response.'@odata.nextLink'){
    do{ $URI = $Response.'@odata.nextLink'
    $response = (Invoke-RestMethod -Uri $uri -Credential $apiCredential )
    $response.value
    }until(!($Response.'@odata.nextLink'))}
    clear-variable ur*
    }

    Works - but not very efficient use of the service I am querying.