I’ve tried dozens of combinations and still get various errors. In the meantime I had no idea but curl is now built into W10 since last year so I’m making the call like this for uploading receipts for OCR:
All my tests with Powershell Invoke-RestMethod failed as well with error code 99 and “{Unable to recognize the file type}”. According to Stackoverflow and other websites, it seems Invoke-RestMethod has problems multi-part api calls. Somewhere else I read that Powershell 6 Core is required.
Anyway, my solution was just like yours, to use curl inside Powershell - this works great.
So, it seems that Powershell Invoke-Expression command inherently does not support multipart file upload. You could use the ‘HttpClient’ for the same. But it is much easier to use cURL with Powershell. We created a code sample for this:
I forgot to come back and post but this is how to do the API call natively in PowerShell. This is preferred because all of the data is already returned in an object and less post processing would be needed as with cURL:
Adding Get-Item actually sends the file itself instead of the path text. This is the same as the @ in cURL which tells it to not send the text, but the file.
I’m also on PowerShell 7, not sure if there is additional code needed for older versions.