0
$header = @{'Authorization'='Basic <auth code value>'}
$ping = Invoke-RestMethod -Uri "https://api.docparser.com/v1/ping" -Headers $header

ping works fine...returns "pong". I then make a request for the Parser ID which is needed for uploading documents. I am able to retrieve this value successfully.

$parser = Invoke-RestMethod -Uri "https://api.docparser.com/v1/parsers" -Headers $header
$parserID = $parser.id

Now here is where I try to upload a pdf, which fails.

$fileToParse = "C:\test.pdf"
$body = @{'file'=$fileToParse}
$uploadDoc = Invoke-RestMethod -Uri "https://api.docparser.com/v1/document/upload/$parserID" -Method Post -Headers $header -ContentType 'multipart/form-data' -Body $body

API response keeps saying "Error: input empty"

This is the documentation from Docparser on how to upload pdfs: enter image description here

Any thoughts on what I'm doing wrong here? Thanks in advance,

Eric

Eric Furspan
  • 558
  • 9
  • 28

1 Answers1

0

The problem is that your body currently just contains the path to your local file. Docparser expects however the content of the file as multipart/form-data.

I never worked with PowerShell, but I think something like this should work for you:

$body = @{
    "file" = Get-Content($fileToParse) -Raw
}

I got the code from this answer: How to send multipart/form-data with PowerShell Invoke-RestMethod

Moritz
  • 1
  • 1
  • Thanks for the reply. I saw that post as well but was not able to get it to work with that. Still giving the error that "input empty" – Eric Furspan Jun 27 '17 at 16:02