API Response Encoded as GzipAll,
I am tapping an internal API and the expected response of the API endpoint is an Excel File. However, when I try to use HTTP request, I receive a response. I am assuming the response is encoded, but I wonder what is a good way to extract the data and use it.
The request I make to the endpoint is as follows:
HeaderStr = "Authorization: Bearer " || AccessToken;
Request = New HTTP Request(
URL( URLDes ),
Method( "Get" ),
Headers( {HeaderStr} )
) << Send;The response I receive is :
"PK"
Re: API Response Encoded as GzipOf Course @bryan_boone. I love to contribute to making JMP better and easier, so it makes our lives easier 
Re: API Response Encoded as Gzip@uday_guntupalli
That's a great usage for having
HTTP Request << Send accept, say, "blob" or "text" arguments.
We'll look into it for JMP 15. Do you want to add it as a Wish List item?
Thanks
-Bryan
Re: API Response Encoded as GzipYou can still use Download instead of Send.
What the above shows is that you have gotten a complete download from your web service. (which is good)
to use Download instead of Send, you can do this:
filename = request << Download("$temp/Test1.xlsx", "replace"); //file is the filename returned by the web server. replace will replace it.
if( !IsEmpty(filename), //a filename is empty if the download fails
//process your file
);
In your case, the mimetype is "text/html" and not an excel spreadsheet. You just named it with and xlsx extension.
If your web service has a different endpoint for excel spreadsheets, use that.
or
If your web service uses and "Accept" header to specify an excel spreadsheet, use that
otherwise
Open the file with a text editor to see what it is. (or a browser) According to the mimetype, you downloaded html.
Re: API Response Encoded as Gzip@bryan_boone,
Thank you for that.

While this is helpful to some degree, I don't see a way other than downloading the data, to de-compress it and interpret within JMP, is my interpretation correct or do you have any other approaches ?
Re: API Response Encoded as GzipWhat you have in your code is that Request is the result of Send.
I *think* what you want is:
request = New Http Request(
URL( URLDes),
Method("GET"),
Headers({HeaderStr})
); //request is the request object
data = request << Send(); //data is the data returned by the web server
That way you can examine the status of request after you've interacted with the service.
I generally think about HTTP Request stuff in 3 steps
Create
Configure
Send
Re: API Response Encoded as Gzip@bryan_boone,
All the messages return the same error . When I try to download the file as @Craige_Hales recommended, it works fine, but none of the diagnostic functions yielded any result 
Re: API Response Encoded as Gzip@Jeff_Perkinson,
Here is the error I receive:
Tried to open: /C:/Users/Test.xlsx
Cannot open table in access or evaluation of 'Open' , Open/*###*/("C:\Users\Test.xlsx")
Re: API Response Encoded as GzipAdditionally,
What does
request << Get Status Message
show?
That will be the status message from the Web Server (200 is good)
There are:
request << Get Status // a number
//booleans
request << Is Successful
request << Has Error
request << Has Client Error
request << Has Server Error
request << Has Information
request << Has Redirection
These will let you give information about the connection and the request that was made to the server.
Re: API Response Encoded as Gziprequest << Send() will return either a blob or text.
To see what you have call:
request << Get Mime Type();
most of them are covered here:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
It is up to the server if they actually add mime type information, but these days, most of them do.
Re: API Response Encoded as Gzip
@uday_guntupalli wrote:
I see that the file gets downloaded, but JMP fails to open it both manually or via script. I tried to intoduce a wait() between the download and open and that didn't help either.

What's the rest of the error message, above the "In the following script..." line?
Are you able to open the downloaded .xlsx file using Excel?
Re: API Response Encoded as Gzip@Craige_Hales,
Thank you Craige. Gets me 95% my way there. I see that the file gets downloaded, but JMP fails to open it both manually or via script. I tried to intoduce a wait() between the download and open and that didn't help either.

Re: API Response Encoded as GzipNot sure how to get a blob back from <
request = New HTTP Request(
URL(
"http://drawoutside.com/abc123.xlsx"
),
Method( "Get" )
);
request<<DOWNLOAD></DOWNLOAD>
JMP's open function imported the xlsx fileJMP's open function imported the xlsx file
@bryan_boone
Re: API Response Encoded as Gzip@Craige_Hales,
Appreciate you trying to guide me when not at work. Let's try tomorrow when you are back. But, here is what I did:
If the response was indeed a zip file, then this didn't work. I think it is an excel file, because I was able to use WriteBin command and content command in R to write it out as an Excel file. However, I have no clue how to capture it in JMP.
Additonally, I also tried this :
This also results in an error :
Error with file: Path is invalid: \PK.
Re: API Response Encoded as GzipActually, excel files probably are zip files, with an xlsx extension. You might already have exactly what you expect.
Re: API Response Encoded as Gzip"PK" is the signature for .zip files. If the data was received in a blob (text won't have the binary data) you can use JMP's zip archive object to open it, something like this (not at work right now...)
za = open(blob,"zip");
za<
za<
(best look in the scripting index.)