@snake14 opened this Issue on November 7th 2022 Contributor

I was updating the WhiteLabel premium plugin to build using PHP 8.1 instead of 8.0 and found that the entry_nb_uniq_visitors and exit_nb_uniq_visitors properties were previously string values and changed to Integer values when using PHP 8.1. I was able to fix the build by having two separate JSON files depending on which PHP version is running, but @mattab made the point that it's better to cast the values to keep them consistent.

Expected Behavior

When I make the following API call, it should return the same result whether I'm using PHP 8.1 or and earlier version:
https://{myMatomoDomain}/index.php?module=API&format=JSON&idSite=1&period=day&date=2022-10-07&method=Actions.getPageTitles&token_auth={myAuthToken}

Current Behavior

When I make the following API call, the entry_nb_uniq_visitors and exit_nb_uniq_visitors properties change typed depending on whether I'm using PHP 8.1 or and earlier version:
https://{myMatomoDomain}/index.php?module=API&format=JSON&idSite=1&period=day&date=2022-10-07&method=Actions.getPageTitles&token_auth={myAuthToken}

Possible Solution

As mentioned above, Matt suggested casting the properties to the expected type to keep the response consistent.

Steps to Reproduce (for Bugs)

  1. Be running PHP 8.1 and call the following API: https://{myMatomoDomain}/index.php?module=API&format=JSON&idSite=1&period=day&date=2022-10-07&method=Actions.getPageTitles&token_auth={myAuthToken}

Context

This broke the WhiteLabel build when I updated it from 8.0 to 8.1. We don't want to break things for clients when they upgrade PHP versions. This is just one API example, but there are probably others.

Your Environment

  • Matomo Version: 4.12.3
  • PHP Version: 8.1
@heurteph-ei commented on November 7th 2022

I think that for compatibility, it should stay as it worked before (string), but maybe in Matomo V5, it should be updated to number as these values are... Numbers!
Is there any impact in the HTTP API?

@sgiehl commented on November 7th 2022 Member

@heurteph-ei I can only agree partially. The API responses might be returned localized, so numbers might be formatted, which will require them to be a string in most cases.

Powered by GitHub Issue Mirror