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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
SOLVED:
I found the solution: Change oRequest.responsetext to oRequest.responsebody
 
Upvote 0
Solution

Forum statistics

Threads
1,224,837
Messages
6,181,255
Members
453,028
Latest member
letswriteafairytale

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