Jump to content

Upload file via API


Santa

Recommended Posts

I'm trying to upload a file to an existing password via API, using Powershell.

I try to get this code to work (from Passwordstates API Manual):

# PowerShell Request
$documentPath = "D:\Build-Specifications.txt"
$uri = "https://passwordstate/api/document/password/123?DocumentName=<DocumentName>&DocumentDescription=SomeDescription"
   
$result = Invoke-RestMethod -Uri $uri -Method Post -InFile $documentPath -ContentType 'multipart/form-data' -Header @{ "APIKey" = "<apikey>" }
Write-Host $result

But I get this error message:

Invoke-RestMethod: "An error has occurred., Value cannot be null.\r\nParameter name: plainText, System.ArgumentNullException

 

Any suggestions about what that can mean?

Link to comment
Share on other sites

  • 1 month later...

Hi @Santa

is the url in your example correct? "DocumentName=<DocumentName>" will not work:

 

-> $uri = "https://passwordstate/api/document/password/210?DocumentName=SomeName&DocumentDescription=SomeDescription"

you could try the Passwordstate-Management PowerShell module (or check the source code).

There exists a function called New-PasswordstateDocument, this should fit your usecase.

 

Module: PowerShell Gallery | passwordstate-management 4.4.48

Example:

 

New-PasswordStateDocument -ID 210 -resourcetype Password -DocumentName VeryImportantScript.ps1 -DocumentDescription "very important powershell script" -Path .\Find-Item.ps1

DocumentID DocumentName
---------- ------------
186        VeryImportantScript.ps1


Result:

image.thumb.png.fab6e39fb190dbbb016d9e7f8432ca19.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...