How to download excel (.xls) file from API in postman?

RestPostmanRest ClientAdvanced Rest-Client

Rest Problem Overview


I am having an API endpoint and Authorization token for that API.

The said API is for .xls report download, how can I view the downloaded .xls file using (if possible) Postman?

If it is not possible using Postman what are the other programmatic ways I should be looking for?

Rest Solutions


Solution 1 - Rest

Try selecting send and download instead of send when you make the request. (the blue button)

https://www.getpostman.com/docs/responses

"For binary response types, you should select Send and download which will let you save the response to your hard disk. You can then view it using the appropriate viewer."

Solution 2 - Rest

You can Just save the response(pdf,doc etc..) by option on the right side of the response in postman check this image postman save response

For more Details check this

https://learning.getpostman.com/docs/postman/sending_api_requests/responses/

Solution 3 - Rest

If the endpoint really is a direct link to the .xls file, you can try the following code to handle downloading:

public static boolean download(final File output, final String source) {
    try {
        if (!output.createNewFile()) {
            throw new RuntimeException("Could not create new file!");
        }
        URL url = new URL(source);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        // Comment in the code in the following line in case the endpoint redirects instead of it being a direct link
        // connection.setInstanceFollowRedirects(true);
        connection.setRequestProperty("AUTH-KEY-PROPERTY-NAME", "yourAuthKey");
        final ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream());
        final FileOutputStream fos = new FileOutputStream(output);
        fos.getChannel().transferFrom(rbc, 0, 1 << 24);
        fos.close();
        return true;
    } catch (final Exception e) {
        e.printStackTrace();
    }
    return false;
}

All you should need to do is set the proper name for the auth token and fill it in.

Example usage:

download(new File("C:\\output.xls"), "http://www.website.com/endpoint");

Solution 4 - Rest

In postman - Have you tried adding the header element 'Accept' as 'application/vnd.ms-excel'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpraxnetView Question on Stackoverflow
Solution 1 - RestJakeView Answer on Stackoverflow
Solution 2 - RestAkitha_MJView Answer on Stackoverflow
Solution 3 - RestnbokmansView Answer on Stackoverflow
Solution 4 - RestjikkuView Answer on Stackoverflow