No announcement yet.

API Request in Powershell with "where" filtering

  • Filter
  • Time
  • Show
Clear All
new posts

  • API Request in Powershell with "where" filtering

    Hi there,

    I am new in the Espo-World. I am trying to write a GET-Request, to get an user id of a contact, filtered by emailAddress. I found the following information, that I can filter the contacts by emailAddress:

    But I can't find any example, how to do it in Powershell. Every try results in a 500 respond from the API.

    $whereFilter = "{

    $compressedWhereFilter = $whereFilter | ConvertFrom-Json | ConvertTo-Json -Depth 10 -Compress

    $headers = New-Object"System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("X-Api-Key", $xApiKey)


    $encodedUri = "{0}Contact?where={1}"-f$baseUrl,[System.Web.HttpUtility]::UrlEncode($compressedWhereFilter)

    return Invoke-RestMethod -Uri $encodedUri -Method 'GET' -Headers $headers | ConvertTo-Json

    That is my last try. Without UrlEncode I get 500 too.

    I would appreciate any help.

    Greeting from Germany

    >>>> EDIT:

    I think I found a good solution:
    $headers = New-Object"System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("X-Api-Key", $xApiKey)

    $url = $baseUrl+"Contact?where[0][type]=equals&where[0][attribute]=emailAddress&where[0][value]="+$mail
    returnInvoke-RestMethod -Uri $url -Method 'GET' -Headers $headers

    Here I got the idea to look at the ready URI to filter the contacts:
    Dzięki za video i pozdrowienia, emillod
    Last edited by paul; 04-09-2022, 07:40 PM. Reason: I found the solution, how it works for me.

  • #2
    Thanks for posting the solution.


    • #3
      As of 7.0.0 search parameters can be passed in JSON format in the parameter `searchParams`. So it's much easier, not requiring building `where` arrays.