How to correctly call API ScheduledReports.addReport

Hi,

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)


<?php
$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]=myemail@mysite.com";
$url .= "&parameters[emailMe]=true";
$url .= "&parameters[displayFormat]=3";
$url .= "&token_auth=$token_auth";

$fetched = file_get_contents($url);

print_r ($fetched);
?>


Here is an example request:

description=description here
format=json
idReport=0
idSegment=
method=ScheduledReports.addReport
module=API
parameters[displayFormat]=1
parameters[emailMe]=true
parameters[evolutionGraph]=false
reportFormat=html
reportType=email
reports[]=Actions_getEntryPageUrls
reports[]=UserCountry_getCountry
token_auth=XXXXXXXXXXX

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]=hello%40text.com”;

I tried

$url .= “&parameters[additionalEmails]=[hello%40text.com]”;

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/analytics.llocally.info/public_html/plugins/ScheduledReports/ScheduledReports.php on line 593 

Backtrace -->

#0 Piwik\Error::errorHandler(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/plugins/ScheduledReports/ScheduledReports.php:593]
#1 Piwik\Plugins\ScheduledReports\ScheduledReports::checkAdditionalEmails(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/plugins/ScheduledReports/ScheduledReports.php:158]
#2 Piwik\Plugins\ScheduledReports\ScheduledReports->validateReportParameters(...) called at [:]
#3 call_user_func_array(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/core/EventDispatcher.php:98]
#4 Piwik\EventDispatcher->postEvent(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/core/Piwik.php:778]
#5 Piwik\Piwik::postEvent(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/plugins/ScheduledReports/API.php:631]
#6 Piwik\Plugins\ScheduledReports\API::validateReportParameters(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/plugins/ScheduledReports/API.php:84]
#7 Piwik\Plugins\ScheduledReports\API->addReport(...) called at [:]
#8 call_user_func_array(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/core/API/Proxy.php:209]
#9 Piwik\API\Proxy->call(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/core/API/Request.php:215]
#10 Piwik\API\Request->process(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/plugins/API/Controller.php:31]
#11 Piwik\Plugins\API\Controller->index(...) called at [:]
#12 call_user_func_array(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/core/FrontController.php:521]
#13 Piwik\FrontController->doDispatch(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/core/FrontController.php:84]
#14 Piwik\FrontController->dispatch(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/core/dispatch.php:30]
#15 require_once(...) called at [/home/llocally/domains/analytics.llocally.info/public_html/index.php:47]


I have sorted it


$url .= "&parameters[additionalEmails][]=hello%40text.com";