Could not use segment in api call to get visiting result

Hello,

I am the customer of innocraft.cloud and I am trying to integrate piwik cloud service with our produciton. The tracking part works very well. But I get problem to use the API to get the visiting result.

E.g. If I run the https://nett.innocraft.cloud/index.php?module=API&method=VisitsSummary.getVisits&idSite=2&period=week&date=2017-10-20&format=JSON&token_auth=ourapitoken , the reuslt is

{
    "value": 11
}

That is correct. But if I try to add segment into the query, I always get zero in reuslt, e.g. https://nett.innocraft.cloud/index.php?module=API&method=VisitsSummary.getVisits&idSite=2&period=week&date=2017-10-20&format=JSON&token_auth=ourapitoken&segment=browserCode==CH , the result is

{
    "value": 0
}

I tried to change the segment value to “browserCode!=CH”, “browserCode!%3DCH” or “browserCode%3D%3DCH”, but the result is always 0 in value.

I tried to look at api documents and FAQ for the whole day, but I could not get this fixed. Could anyone give me some hints in this. Thank you very much.

I also found that I can make this work in piwik demo sysem:
https://demo.piwik.org/index.php?module=API&method=VisitsSummary.getVisits&idSite=3&period=week&date=2017-10-20&format=JSON&token_auth=anonymous&segment=browserCode!=CH , and the result is

{
    "value": 91
}

I could not figure out why similar query could not work in my account in innocraft.cloud

It will be appreciated if anyone could give me suggestion in this.

Jerry Liu

I got reply from support of innocraft that I must manually created the segment in the UI editor and waiting a few hours until it is available in the api.

Yes, it works now with segement. I need to take a look at the api to see if I can use api to create segment instead of creating in the UI.

Thanks for the support.

Jerry

Hi,

This is the API for creating segments:

https://developer.piwik.org/api-reference/reporting-api#SegmentEditor

Just noticed there is an typo and opened a pull request to fix it:

Hi Lukas,

Thank you very much.

Best regards,
Jerry