KoolReport's Forum

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

I need to connect with API and pass that data in JSON to create a reports DATASTORE #2371

Open Javier Gallardo opened this topic on on Oct 4, 2021 - 10 comments

Javier Gallardo commented on Oct 4, 2021

You do something like this:

ReportBoard.php

<?php

namespace space\report;

use \koolreport\dashboard\CustomBoard;

class ReportBoard extends CustomBoard {

protected function actionIndex($request, $response)
{
    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => 'link',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
      CURLOPT_HTTPHEADER => array(
        'Authorization: token'
      ),
    ));
    
    $response = curl_exec($curl);
    curl_close($curl);
    $json = $response;
    $arr = json_decode($json, true);
    $result = [];
    foreach($arr["projects"] as $project)
    {
        array_push($result,[
            "id"=>$arr["projects"]["id"],
            "name"=>$arr["projects"]["name"],
            "status.name"=>$arr["projects"]["status"]["name"]
        ]);
    }

    $this->renderView([
        "result"=>$result
    ]);
}

} In the view file ReportBoard.view.php

<?php

namespace space\report;

use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\LineChart;
//You can access through $this->result

THIS LINE HAVE A MISTAKE $result = $this->params()["result"];

var_dump($result);

?> <div class="report-content">

<div class="text-center">
    <h1>Join</h1>
    <p class="lead">Primer Grafico</p>
</div>


        <h5 class="text-center">Primera tabla</h5>

<?php //Use associate array

        Table::create(array(
            "dataSource"=>$this->dataStore("array-datasource-name"),
            "cssClass"=>array(
                "table"=>"table-bordered table-striped table-hover"
            )
        ));
?>

</div>

Javier Gallardo commented on Oct 4, 2021

when I put the api in Report.php this is the error

Javier Gallardo commented on Oct 4, 2021
<?php

namespace space\report;

    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\LineChart;

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'link',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: TOKEN'
  ),
));

$response = curl_exec($curl);
curl_close($curl);
$json = $response;
$arr = json_decode($json, true);
$result = [];
foreach($arr["projects"] as $project)
{
    array_push($result,[
THIS LINE HAVE A MISTAKE        "id"=>$arr["projects"]["id"],
        "name"=>$arr["projects"]["name"],
        "status.name"=>$arr["projects"]["status"]["name"]
    ]);
}

$this->src("array-datasource-name")->load($result);

    //You can access through $this->result
    $result = $this->params()["result"];
    var_dump($result);
?>
<div class="report-content">
    <div class="text-center">
        <h1>Join</h1>
        <p class="lead">Primer Grafico</p>
    </div>
    

            <h5 class="text-center">Primera tabla</h5>
   <?php
//Use associate array
            Table::create(array(
                "dataSource"=>$this->dataStore("array-datasource-name"),
                "cssClass"=>array(
                    "table"=>"table-bordered table-striped table-hover"
                )
            ));
    ?>
</div>
Javier Gallardo commented on Oct 4, 2021

when I put the api in ReportBoard.view this is the error

Javier Gallardo commented on Oct 7, 2021

=

KoolReport commented on Oct 7, 2021

We have show you how to convert json from your API to array form that KoolReport can understand. Your job now is to look into your API returned json and figure out its structure and locate needed fields. If you are not familiar with this , you may find a good dev to work with you on this.

Javier Gallardo commented on Oct 9, 2021

:(

Javier Gallardo commented on Oct 9, 2021

All this that you taught me does not work, could you help me why it fails?

daniel commented on Nov 15, 2021

???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

KoolReport commented on Nov 16, 2021

????

"Your job now is to look into your API returned json and figure out its structure and locate needed fields" -> we could not help you on this as we do not know content of your API and in fact, it does not belongs to our product. As long as you have your data and converted to the format I have shown you, it will work.

daniel commented on Nov 16, 2021

.

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
None yet

None