KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

API in Koolreport for data IMP #234

Open Rohit opened this topic on on Mar 26, 2018 - 3 comments

Rohit commented on Mar 26, 2018

Can we use API for data, my APIs will bring data in JSON format so can i pass that data for creating report.

Please reply its urgent

KoolReport commented on Mar 26, 2018

Sure you can, please use the ArrayDataSource like following;

class MyReport extends \koolreport\KoolReport
{
    function settings()
    {
        return array(
            "dataSources"=>array(
                "apiarray"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"associate",        
                )
            )
        )
    }
    function setup()
    {
        //Connect to your api here and load json, parse json string to array and
        //store the data in the associate format like below:
        // $data = array(
        //     array("customerName"=>"Johny Deep","dollar_sales"=>100),
        //     array("customerName"=>"Angelina Jolie","dollar_sales"=>200),
        //     array("customerName"=>"Brad Pitt","dollar_sales"=>200),
        //     array("customerName"=>"Nocole Kidman","dollar_sales"=>100),
        // )

        $this->src("apiarray")->load($data)
        ->pipe(...)
        ...
        -.pipe($this->dataStore("result"));
    }
}
Mazmur commented on Feb 16, 2019

How can if I have an API file in https://www.example.com/api/store1 ?

Regards Mazmur

KoolReport commented on Feb 16, 2019

For example you have a SaleByMonth report which is of course return total sale by month. You can make the api like this:

https://www.example.com/api/salereport?type=month

And then you can do:

if($_GET("type")=="month")
{
    $report = new SaleByMonth;
    $report->run();
    echo $report->dataStore("result")->toJson();
}

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None