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 does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
SOLVED:
I found the solution: Change oRequest.responsetext to oRequest.responsebody
 
Upvote 0
Solution

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

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