dnewsholme / PasswordState-Management

Powershell Module For Management of Passwordstate. (Powershell Core Compatible)
GNU General Public License v3.0
39 stars 14 forks source link

Save-PasswordStateDocument not saving document #164

Closed gregbeck closed 5 months ago

gregbeck commented 5 months ago

The Save-PasswordStateDocument script isn't working for me. I am connecting to PasswordState v9. Using Powershell 5.1 using the Windows Integrated API.

The main part of the Save-PasswordStateDocument script looks like:

$output += Get-PasswordStateResource `
                -uri "/api/document/$($resourcetype)/$($ID)/$documentID" `
                -extraparams @{"OutFile" = "$Path"} `
                -contenttype 'multipart/form-data' `
                -ErrorAction stop

It seems Get-PasswordStateResource requires a headers hashtable to be passed in the extraparams for it to add the OutFile option to the command. It seems to work if I pass an empty 'Headers' hashtable in the command. Although the script should probably have a 'Reason' option to match the other commands.

I am not sure if it is a v8 vs v9 PasswordState thing but the URL also doesn't match the v9 documentation. There is an extra $($ID) that doesn't match anything.

In the documentation the URL is https://passwordstate/winapi/document/passwordlist/<documentid>

dnewsholme commented 5 months ago

@gregbeck Thanks for raising this. There is indeed a bug in the url with the extra ID. It also isn't passing the extra parameters through as expected. The @{Outfile=$path} hash table should be passed on to invoke-restmethod and added as a parameter to ensure the file is saved. This wasn't happening due to an incorrect evaluation against $extraparam.headers instead of $extraparams. I've fixed this in the Add/Get/Set/Remove-PasswordstateResource private functions and it works as intended again.

dnewsholme commented 5 months ago

Build 4.4.49 now available in the PSGallery. Which resolves this issue.