Thursday 20 September 2018

Using curl to fetch from a URL which outputs a dynamically generated Excel file

We often come across this case where another company provides us with a url which we can  use via a browser to get an excel or pdf report. 
Usually it also accepts one or more parameters, which are used by the backend script in the report generation process.
How does one call this via CURL to allow our application to fetch the reports automatically  based on some pre defined schedule, or in a bulk fashion for a set of running parameters.
Its possible and to do it  one can use the delimiters -o and -j
Lets say our url looks something like this:
http://sample.example.com/xyz?type=xlsx&o=1&rt=1&id=11887&user=1
 Then we can use the call below to achieve this.

curl -o -j "http://sample.example.com/xyz?type=xlsx&o=1&rt=1&id=11887&user=1"