API call idSite=all error - website id was set to '0'

Hello,

We have migrated our old piwik plateform (2.16.1) to matomo 3.9.1 and a call to matomo API with the parameter “idsite=all” return the error : “An unexpected website was found in the request: website id was set to ‘0’ .”
(example of request : https://example.com/matomo/index.php?format=xml&module=API&method=API.getProcessedReport&idSite=all&date=yesterday&period=day&apiModule=UserCountry&apiAction=getCountry&token_auth=xxx&language=fr)
The same API call to piwik plateforme works. Therefore, with a specific idsite the API call works for both plateforms (piwik and matomo).

I have read some reference of this issue on gitlab but it seems to have been fix on a previous version of matomo. I tried to upgrade matomo plateform at the latest version and i’m still facing the problem.

Am I facing a global bug or is there a solution (even temporary) i can apply ?

Thank you for your help.

Regards.

PierreG

Hi,

That bug was fixed in 3.13.3.

I’d very strongly recommend you to update to the latest version, but in the meantime that patch might fix it:

diff --git a/plugins/VisitFrequency/API.php b/plugins/VisitFrequency/API.php
index 854b0de5f5b..afc93fe6362 100644
--- a/plugins/VisitFrequency/API.php
+++ b/plugins/VisitFrequency/API.php
@@ -49,7 +49,10 @@ public function get($idSite, $period, $date, $segment = false, $columns = false)
         $columns = Piwik::getArrayFromApiParameter($columns);
 
         /** @var \Piwik\DataTable\DataTableInterface $resultSet */
-        if (Period::isMultiplePeriod($date, $period)) {
+        if ($idSite === 'all') {
+            $resultSet = new DataTable\Map();
+            $resultSet->setKeyName('idSite');
+        } else if (Period::isMultiplePeriod($date, $period)) {
             $resultSet = new DataTable\Map();
             $resultSet->setKeyName('period');
         } else {

Hi,

Thanks a lot for your fast answer.
After testing the upgrade of our matomo plateform to the latest version (3.14.0), the problem is still present.

The API.php file of VisitFrequency plugin has been updated with the upgrade and I see the adds for “idsite === ‘all’”.
By searching files named “API.php”, I found 53 others files in the others plugins installed. Maybe the problem I’m face to is from another plugin.

We are looking for another way to implement our API calls to be able to extract the same content has we did on our piwik plateform but we are affraid of the time and charge it could represent for the plateform (we think to loop on the different idsite we have to replace the unique call with idsite=all).

If by any chance there is another solution i can explore, I would be glad to get your advices.

Thank you again for your help.

Regards.

PierreG

Hi,

Could you share the URL of the API request you are trying to make?

I forgot to precise again the URL in my answer. There it is :

https://example.com/matomo/index.php?module=API&method=API.get&idSite=all&period=day&date=yesterday&filter_limit=-1&format=json&token_auth=xxxxx

Hi,

It seems like supporting this for all report types might be more complicated than it looks. I’d personally recommend you to just loop locally and make API requests for all of your siteids separately.