Jump to content

Documents API


Recommended Posts

Hello, 

 

How to identify what type of file I get as a response when I use the /api/document/passwordlist/<DocumentID> API. 

 

I get the response, and if I already know the file type, and save it, it works, but if i do not know the file type, then I dont know how to save it. 

Can i append something to the header to get the filename and description somehow? 

 

I use this in Powershell: 
Invoke-Restmethod -Method GET -Uri $PasswordstateUrl -Header @{ "APIKey" = "$Apikey" } -OutFile myfile.abc

 

Thank you. 

Link to comment
Share on other sites

Hi Johan,

 

What you've pointed out is a good point if you do not know the document name. I think we'll need to add another method to the API to retreieve the document name separately, but below is how you can do it for the moment - update the filename path as appropriate, and IDs and API Key.

 

$PasswordstateUrl = '/api/document/password/<DocumentID>'
 

#Read and output key to file
$result = Invoke-WebRequest -Method GET -Uri $PasswordstateUrl -Header @{ "APIKey" = "$Apikey" }
$contentDisposition = $result.Headers.'Content-Disposition'
$fileName = $contentDisposition.Split("=")[1].Replace("`"", "")
$fileName = Join-Path "c:\temp" $fileName

Invoke-WebRequest -Method GET -Uri $PasswordstateUrl -Header @{ "APIKey" = "$Apikey" } -OutFile $filename

 

Regards

Click Studios

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...