Hi,
I have some code that calls an API which is returning a bunch of data (over 1 MB) in a zipped format. When I run this call under PostMan, I can just "save as" the results and I have my file. However, I want to run this process from Excel. The code below is making the API request and receiving the data, but when I try to write/put it to a file, the resulting file is corrupted and can't be opened with the unzip programs. I am sure that my binary data from the API is getting stepped on in translation, but I'm not API savvy enough to know just where. Any ideas or examples I can try? Thanks!
I have some code that calls an API which is returning a bunch of data (over 1 MB) in a zipped format. When I run this call under PostMan, I can just "save as" the results and I have my file. However, I want to run this process from Excel. The code below is making the API request and receiving the data, but when I try to write/put it to a file, the resulting file is corrupted and can't be opened with the unzip programs. I am sure that my binary data from the API is getting stepped on in translation, but I'm not API savvy enough to know just where. Any ideas or examples I can try? Thanks!
VBA Code:
Dim APIBinary() as Byte
.
.
.
APIString = "https://api2.watttime.org/v2/historical?ba=NYISO_NYC"
oRequest.Open "GET", APIString, False
oRequest.setRequestHeader "Authorization", "Bearer " + Token
oRequest.Send
APIBinary = oRequest.responsetext
'Save results to zip file
OutputFileName = "WattTime Data-" & Int(Time * 100000) & ".zip"
'Open the output file
OutputFileName = ThisWorkbook.Path & "\" & OutputFileName
FileNum = FreeFile
Open OutputFileName For Binary Access Write As FileNum
Put #FileNum, , APIBinary
Close #FileNum