318

I have an API endpoint and an 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?

axnet
  • 5,146
  • 3
  • 25
  • 45
  • 4
    @nbokmans I want to download .xls file provided by backend when i use postman, i am not able to view .xls file properly, its all unicodes and special characters. What I need is, If there is any other programmatic way apart from postman for firing an api and downloading .xls file on my pc – axnet Aug 16 '16 at 15:03
  • @nbokmans Thanks for reply, it just starts download, it doesn't give any location. – axnet Aug 16 '16 at 15:50

5 Answers5

746

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

Screenshot showing "Send and Download" button in postman

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."

Gangula
  • 5,193
  • 4
  • 30
  • 59
Jake
  • 8,167
  • 1
  • 19
  • 19
29

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/

Akitha_MJ
  • 3,882
  • 25
  • 20
  • 1
    It seems to ok. But there is not Save Response option for GET or POST requests. Should I use **Send and Download** option on Postman? –  Sep 05 '21 at 17:18
  • for each request, you will get an option to save the response, but as you mentioned you can use the send & save option as well – Akitha_MJ Aug 03 '22 at 06:24
10

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");
nbokmans
  • 5,492
  • 4
  • 35
  • 59
  • 1
    This code works for me, though for my info if my endpoint would not have been direct link, what change would i need to do in above code snippet? – axnet Aug 16 '16 at 19:34
6

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

jikku
  • 641
  • 1
  • 6
  • 18
5

For UI, choose Send and Download button instead of Send button in Postman: enter image description here

Hana Hasanah
  • 145
  • 1
  • 6