Here's another post for anyone following this thread and interested in using AHK with Docparser. My previous post shows how to download the parsed data as key-value pairs (nested JSON objects). It also mentions that there's some header data (before the actual parsed data from the PDF file) and it turns out that the header data contains a link to the actual Excel file that works perfectly with AHK's UrlDownloadToFile
. The key is media_link_data
and the value following it is the URL of the XLSX file that contains the parsed data. A minor modification of one of the scripts above is able to download the XLSX file, as shown in the tested script below:
Code: Select all
MsgBox,4112,Fatal Error,Unable to create HTTP object
UsernamePasswordBase64:="this is your Base64-encoded username with a null password"
ParserID:="this is the unique ID of your parser"
DocumentID:="this is the unique ID of your document"
URL:="https://api.docparser.com/v1/results/" . ParserID . "/" . DocumentID
oHTTP.SetRequestHeader("Authorization","Basic " UsernamePasswordBase64)
MediaLinkStr:="""media_link_data"":""" ; key for Excel URL
MsgBox,4112,Fatal Error,%MediaLinkStr% not found in response
MsgBox,4112,Fatal Error,Closing quote on Excel URL not found in response
ExcelLink:=StrReplace(ExcelLink,"\") ; backslash is escape char for forward slashes in URL - remove all
MsgBox,4112,Fatal Error,Error Level=%ErrorLevel% trying to download:`n%ExcelLink%`nto:`n%ExcelFileDownload%
; Excel file was downloaded
My plan is to turn all the code developed in this thread into functions, something along these lines:
Code: Select all
I also plan to make it more robust, with lots of error checking, including Try-Catch
pairs where appropriate. But that's for the future with an unknown ETA. In the meantime, I hope that the code in here helps anyone looking to call the Docparser API with AHK. Regards, Joe