Matomo API to fetch results for idSite=all in csv, xls or tsv format not working for normal users

Hello,

When we try to fetch visits data using Matomo API with idSite=all in csv or xls format it is not working for normal users even with admin access. Whereas it works fine for super users. Json, xml and html works fine for all users. Are there any extra settings that needs to be enabled for this to work for normal users?

Thanks & Regards,
Kavana

Hello,

I confirm, I have the exact same issue, when I use the following URL: https://myserver/piwik/index.php?module=API&method=VisitsSummary.getVisits&idSite=all&period=day&date=yesterday&format=csv&token_auth=TOKEN it’s working well with super user not for normal user or admin access.

Can you confirm the issue ? is there a workaround ?

Regards

Hi,

To me that sounded strange, but I tested it and can confirm that the combination of a non-superuser, csv and idSite=all doesn’t work.

I’ll add a GitHub issue.

Hi @Thibaut and @kavana_t:

Can you please test if this change fixes the issue for you

diff --git a/plugins/API/Renderer/Csv.php b/plugins/API/Renderer/Csv.php
index e2d7baa0dca..34c81b31d43 100644
--- a/plugins/API/Renderer/Csv.php
+++ b/plugins/API/Renderer/Csv.php
@@ -23,7 +23,7 @@ public function renderSuccess($message)
 
     /**
      * @param $message
-     * @param Exception|\Throwable $exception
+     * @param \Exception|\Throwable $exception
      * @return string
      */
     public function renderException($message, $exception)
@@ -35,7 +35,11 @@ public function renderException($message, $exception)
     public function renderDataTable($dataTable)
     {
         $convertToUnicode = Common::getRequestVar('convertToUnicode', true, 'int', $this->request);
-        $idSite = Common::getRequestVar('idSite', false, 'int', $this->request);
+        $idSite = Common::getRequestVar('idSite', 0, 'int', $this->request);
+
+        if (empty($idSite)) {
+            $idSite = 'all';
+        }
 
         /** @var \Piwik\DataTable\Renderer\Csv $tableRenderer */
         $tableRenderer = $this->buildDataTableRenderer($dataTable);
diff --git a/plugins/Ecommerce/Reports/Base.php b/plugins/Ecommerce/Reports/Base.php
index 775f3e1446f..5d8cc912e4a 100644
--- a/plugins/Ecommerce/Reports/Base.php
+++ b/plugins/Ecommerce/Reports/Base.php
@@ -57,7 +57,7 @@ private function isEcommerceEnabledByInfos($infos)
     {
         $idSite = $infos['idSite'];
 
-        if (empty($idSite)) {
+        if (empty($idSite) || 'all' === $idSite) {
             return false;
         }
 
diff --git a/plugins/ImageGraph/ImageGraph.php b/plugins/ImageGraph/ImageGraph.php
index 6706691b3e2..37834fc44e1 100644
--- a/plugins/ImageGraph/ImageGraph.php
+++ b/plugins/ImageGraph/ImageGraph.php
@@ -56,7 +56,7 @@ public function getReportMetadata(&$reports, $info)
         $idSite = $info['idSite'];
 
         // If only one website is selected, we add the Graph URL
-        if (empty($idSite)) {
+        if (empty($idSite) || 'all' === $idSite) {
             return;
         }