Skip Navigation
Expand
How do I run a report in ConnectPHP?
Answer ID 10042   |   Last Review Date 03/13/2019

How do I run a report in the ConnectPHP API?

Environment:

Oracle B2C Service (OSvC), all supported versions

Resolution:

Before running the report through ConnectPHP there are a few checks that need to be done:

  1. Make sure the report is public (not private)
  2. Make sure the report is associated to the interface your script runs on
  3. If you use a staff account to authenticate in ConnectPHP, make sure the associated profile has "Open" access to the report. This can be verified in the agent desktop console by opening a profile from Configuration -> Staff Management -> Profiles and then selecting Analytics from the ribbon.
  4. If you use a staff account, also make sure to enable access to the interface the script runs on from the Interfaces section in the ribbon on the account profile.
  5. Make sure you identify the ID of the report. The ID can be found in the Reports Explorer after adding the ID column or from the Report Definition upon running the report from the console.

Below is an example on how you would execute report ID 101228:

$ar= RNCPHP\AnalyticsReport::fetch(101228);
$arr= $ar->run();
for ( $ii = $arr->count(); $ii--; ) {
    $row = $arr->next();
    echo( "Columns: "
    .join( ',', array_keys( $row ) ) . "\n" );
    echo( "Values: "
    .join( ',', $row ) . "\n" );
}

The code snippet simply fetches a report, executes it with the default filters and then prints the columns and values on the screen.

If you need to specify a filter value when executing the report, you would do something like this:

$status_filter= new RNCPHP\AnalyticsReportSearchFilter;
$status_filter->Name = 'contacts.email';
$status_filter->Values = array( 'name@example.com' );
$filters = new RNCPHP\AnalyticsReportSearchFilterArray;
$filters[] = $status_filter;
$ar= RNCPHP\AnalyticsReport::fetch(101228);
$arr= $ar->run( 0, $filters );
for ( $ii = $arr->count(); $ii--; ) {
    $row = $arr->next();
    echo( "Columns: "
    .join( ',', array_keys( $row ) ) . "\n" );
    echo( "Values: "
    .join( ',', $row ) . "\n" );
}


The above snippet runs the report by explicitly using the value "name@example.com" for the "contacts.email" filter. This is an unnamed filter and should be replaced with the actual name of the filter if the filter has a name. If the filter does not have a name, the table.column format should be used. Note that if the specific table.column does not exist as a filter, it would not work. A notable limitation when running a report through the ConnectPHP API is that the number of returned results is limited to 10,000. If more results are needed, multiple report executions would be required to achieve the requirement. In this case, an offset number would need to be explicitly specified as well to make sure you don't get duplicate results.

For more information please review the ConnectPHP documentation:

Answer ID 5169: Technical Documentation and Sample Code

Available Languages for this Answer:

Notify Me
The page will refresh upon submission. Any pending input will be lost.