Saving Binary Zip Data Returned Via API

Eldrod

Board Regular
Joined
Mar 11, 2010
Messages
76
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!
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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
SOLVED:
I found the solution: Change oRequest.responsetext to oRequest.responsebody
 
Upvote 0
Solution

Forum statistics

Threads
1,223,923
Messages
6,175,392
Members
452,640
Latest member
steveridge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top