0

I'm trying to send bulk requests to the Piwik tracking api (/piwik.php) and I'm running into a problem. When I send the request (from a PHP script over ajax, curl and from fiddler2), I'm receiving the following:

Debug enabled - Input parameters:<br/>array ( )
token_auth is authenticated!
Loading plugins: { Provider,Goals,UserCountry }
Current datetime: 2013-05-02 16:02:27
The request is invalid: empty request, or maybe tracking is disabled in the config.ini.php via record_statistics=0

My post looks like this:

{"requests":["%3Fidsite%3D1%26url%3Dhttp%3A%2F%2Fexample.org%26action_name%3DTest+bulk+log+Pageview%26rec%3D1"],"token_auth":"mytokenhere"}

Which is the example straight from their website. I've made sure to set the content-type to "Content-Type: application/json" and that my configuration has record_statistics = 1 explicitly defined.

According to the documentation, this should all work, but I'm still getting the empty request. The import_logs.py script also works, so I know that the general bulk importing is not broken, but I'm not sure how to get the program to accept my data. Has anyone had any luck with it?

Thanks!

J_D
  • 681
  • 2
  • 8
  • 22

2 Answers2

1

Perhaps the problem with your request is that your query strings are URL encoded, but they don't need to be since they're part of the POST body.

Your POST should be like this instead:

{"requests":["?idsite=1&url=http://example.org&action_name=Test+bulk+log+Pageview&rec=1"],"token_auth":"mytokenhere"}

See the example at the docs for the Bulk Tracking API: http://piwik.org/docs/tracking-api/reference/#toc-advanced-bulk-tracking-requests

nullability
  • 10,545
  • 3
  • 45
  • 63
  • Thanks nullability. It was a bit of that and that their documentation was wrong on what the json string needed to be that was sent. I was able to get Fiddler installed on my server and had that listening when I ran their import script and found out how the request is really supposed to be formed. – J_D May 03 '13 at 14:26
1

Figured out what was wrong. Their documentation was incorrect in how the request needed to be formatted. First, URL Encoded data was unnecessary. Second, the JSON string needs to look like this:

{
"requests": [
    {
        "apiv": "1",
        "bots": "1",
        "idsite": "1",
        "download": "",
        "cdt": "",
        "dp": "",
        "url": "",
        "urlref": "",
        "cip": "",
        "ua": "",
        "_cvar": {
            "1": [
                "Not-Bot",
                "Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_5;+en-US)+AppleWebKit/534.10+(KHTML,+like+Gecko)+Chrome/8.0.552.231+Safari/534.10"
            ]
        },
        "rec": "1"
    }
  ]
}

Not all of those pieces of data need to be sent, but that's the format necessary. After that it's just data cleansing.

J_D
  • 681
  • 2
  • 8
  • 22
  • This does not work in latest Piwik 2. following user guide at http://developer.piwik.org/api-reference/tracking-api#bulk-tracking works. – NickT May 23 '14 at 03:31
  • Thanks NickT, this was from about a year ago and I was going back-and-forth with their developers about this, because using Fiddler I could see what was being sent and their docs didn't match what actually needed to be sent. Glad to see that everything is lining up properly now in their code – J_D May 23 '14 at 13:20