How to correctly call API ScheduledReports.addReport

(Alan) #1


I am struggling to find enough info to be able to successfully add a scheduled report. The documentation for ScheduledReports.addReport has no examples.

In my test script, that I got working as the example PHP to fetch keywords , I adapted sing the spec for ScheduledReports.addReport and looking at data (API key etc removed) I created the script below, but it doesn’t do anything.

I drove my argument data from what IO could see in the database ‘report’ table but I am pretty much guessing how the two query strings for
reports and parameters might be formatted.

For reports I saw in the API documentation arrays as query string parameters, so used report[0] etc, but for parameters I am guessing.

So can anyone with some experience of this give me a pointer. Thanks

(script below has had API / domain / email removed of course to protect the innocent)

$token_auth = 'my real token';

//ScheduledReports.addReport (idSite, description, period, hour, reportType, reportFormat, reports, parameters, idSegment = '')

$url = "http://my analytics domain/";
$url .= "?module=API&method=ScheduledReports.addReport";
$url .= "&idSite=2&period=day&hour=0";
$url .= "&reportType=email";
$url .= "&reportFormat=html";
$url .= "&reports[0]=VisitsSummary_get";
$url .= "&reports[1]=Actions_getEntryPageUrls";
$url .= "&parameters[additionalEmails]";
$url .= "&parameters[emailMe]=true";
$url .= "&parameters[displayFormat]=3";
$url .= "&token_auth=$token_auth";

$fetched = file_get_contents($url);

print_r ($fetched);

(Matthieu Aubry) #2

Here is an example request:

description=description here

(Alan) #3

Many thanks, with abit of tweaking I managed to get the basics going

BUT I still have one issue

that is how to specifiy the additionalEmails parameter in a query string.

The parameter is causing a ‘bail out’ as it expects an array when sent as (array expected, string provided)

$url .= “&parameters[additionalEmails]”;

I tried

$url .= “&parameters[additionalEmails]=[]”;

with the same result

So anyone know the correct way of specifying an array within an array in a query string?

There is an error. Please report the message (Piwik 2.1.0) and full backtrace in the Piwik forums (please do a Search first as it might have been reported already!).

Warning: Invalid argument supplied for foreach() in /home/llocally/domains/ on line 593 

Backtrace -->

#0 Piwik\Error::errorHandler(...) called at [/home/llocally/domains/]
#1 Piwik\Plugins\ScheduledReports\ScheduledReports::checkAdditionalEmails(...) called at [/home/llocally/domains/]
#2 Piwik\Plugins\ScheduledReports\ScheduledReports->validateReportParameters(...) called at [:]
#3 call_user_func_array(...) called at [/home/llocally/domains/]
#4 Piwik\EventDispatcher->postEvent(...) called at [/home/llocally/domains/]
#5 Piwik\Piwik::postEvent(...) called at [/home/llocally/domains/]
#6 Piwik\Plugins\ScheduledReports\API::validateReportParameters(...) called at [/home/llocally/domains/]
#7 Piwik\Plugins\ScheduledReports\API->addReport(...) called at [:]
#8 call_user_func_array(...) called at [/home/llocally/domains/]
#9 Piwik\API\Proxy->call(...) called at [/home/llocally/domains/]
#10 Piwik\API\Request->process(...) called at [/home/llocally/domains/]
#11 Piwik\Plugins\API\Controller->index(...) called at [:]
#12 call_user_func_array(...) called at [/home/llocally/domains/]
#13 Piwik\FrontController->doDispatch(...) called at [/home/llocally/domains/]
#14 Piwik\FrontController->dispatch(...) called at [/home/llocally/domains/]
#15 require_once(...) called at [/home/llocally/domains/]

(Alan) #4

I have sorted it

$url .= "&parameters[additionalEmails][]";