0

I am trying to invoke an API in Powershell with GET requests. I am familiar with filtering the response by sending a Powershell hashtable in the "Body" parameter as"

Invoke-RestMethod -Uri $uri -Body $filters -Headers $headers

But the hashtables only allow me to filter with the equals operator. As the hashtable looks sort of like

$filter = @{id="fl201"; name="john"}

I need to use comparisons other than "equals", more importantly "-ne" and "-like" and so on. I can filter them after I get the response from Invoke-RestMethod but the response will be so huge that the request itself times out. The API is only a middleware between the client and the database and does nothing other than looking for rows that match the values of the fields in the body. So, is there any way I can do complex filters along with the web request? Thanks in advance.

  • 1
    What you can do entirely depends on the kind of web service you are using, what API it provides. You don't give any information about that. – zett42 Feb 12 '21 at 19:58
  • @zett42 Sorry, edited the post. And, no, I do not know the functionality behind the API but the response pretty much indicates it spits out the values that the fields match in the body. – Sanjiv Pradhanang Feb 12 '21 at 20:11
  • 1
    Then the answer is "no". If the web service doesn't provide an API to do more complex filtering, you have to rely on PowerShell doing the filtering on the client side, e. g. using `Where-Object`. – zett42 Feb 12 '21 at 20:14

0 Answers0