Custom API method for export report by ID

I’m trying to add a method to export a report by id.
has many reports.
created an API method
API return JSON = OK.

but
calling any sql always returns the same result:

  "current_field": null,
  "field_count": null,
  "lengths": null,
  "num_rows": null,
  "type": null

why?

and

$module->db->database =   {
        "affected_rows": null,
        "client_info": null,
        "client_version": null,
        "connect_errno": null,
        "connect_error": null,
        "errno": null,
        "error": null,
        "error_list": null,
        "field_count": null,
        "host_info": null,
        "info": null,
        "insert_id": null,
        "server_info": null,
        "server_version": null,
        "stat": null,
        "sqlstate": null,
        "protocol_version": null,
        "thread_id": null,
        "warning_count": null
}

only null

try code:
\service\v4\SugarWebServiceImplv4.php

    public function get_report()
    {
        include_once "modules/AOR_Reports/AOR_Report.php";

        $report = new AOR_Report();
        $report->report_module = 'AOR_Reports';
        $report->id = $_REQUEST['report_id'];

        $report->build_api_report();
    }

\modules\AOR_Reports\AOR_Report.php

    public function build_api_report()
    {
        $this->build_report_csv(); // default CSV export method
    }

result: return only csv headers

Hello @and_y87,
It seems that the SQL query is not returning any result, which could be due to various reasons such as incorrect SQL query syntax, permission issues, or empty data. You can try debugging the SQL query by printing it out and executing it manually to see if it returns any results.

Regarding the $module->db object returning null values, it could be because the $module object is not properly initialized or the database connection is not established. You can try checking if the $module object exists and if the database connection is established before accessing the db object.

In addition, you may want to check if the build_report_csv() method is properly implemented and returning the expected result. You can try debugging the method by printing out some variables and checking the execution flow.

Finally, you can also check the SuiteCRM logs to see if there are any error messages that could help you identify the issue.