Jump to content

Searching for folders using REST API


Meelis Nigols

Recommended Posts

Another thing that was unexpected.

 

When searching folders by name, it turns out that folder name string is used for substring search.  For example, when using next URL for search: 

https://passwordstate/winapi/folders/?FolderName=Folder1&TreePath=\Test

then results include folders with following names (and treepaths):

  • Folder1 (\Test\Folder1)
  • Folder10 (\Test\Folder10)
  • Subfolder1 (\Test\Folder*\Subfolder1 - serveral folders)
  • Subfolder10 (\Test\Folder*\Subfolder10 - serveral folders)

 

How can I perform search with exact match?  Without that i have to construct desired TreePath and then compare all returned results to that, if I want to get only folder I'm searching for...

 

My PasswordState build number is 8706.

Link to comment
Share on other sites

Hi Meelis,

 

Unfortunately under these circumstances, we do not have the ability to do an exact match under a nested tree structure, so I've created this script which does a bit of data manipulation to find the exact Folder ID.  This is Powershell once again and you'll need to change your URL, and both the variables at the top of the script for your treepath and folder name. 

 

 

 

$PasswordstateUrl = "https://sandbox.halox.net"
$APIKey = "4ca37695823bdfe9285afe3bc3467d87"

 

#Set the search terms for the fodler you wish to look up in the variable below
$Name = "Folder 1"
$TreePath = "Test"

 

# Construct the URL
$FullUrl = "$PasswordstateUrl/api/folders/?FolderName=$Name&TreePath=$TreePath"

 

# Execute the search
$result = Invoke-Restmethod -Method GET -Uri $FullURL -Header @{ "APIKey" = $APIKey }

 

# Filter on Results to get FolderID
$Folder = $result  | select-object folderid, foldername | where {$_.foldername -eq "$Name"}
$FolderID = $Folder.FolderID
Write-Output $FolderID

 

 

 

 

 

Regards,

Support

Link to comment
Share on other sites

5 hours ago, support said:

 

Unfortunately under these circumstances, we do not have the ability to do an exact match under a nested tree structure, so I've created this script which does a bit of data manipulation to find the exact Folder ID.

 

 

Would it be possible to change documentation and state there, that search performs substring search?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...