How to call the OCR REST API in PowerShell

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:

$Form = @{

            isTable = "true"

            scale   = "true"

            file    = Get-Item -Path "C:\Path\mydoc.pdf"

        }

        Invoke-RestMethod -Method Post -Uri "https://api.ocr.space/Parse/Image" -Headers @{apikey = "0000000"} -Form $Form

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.

1 Like