Why do I get this XML parsing error?

Hello,

I’m using Piwik for the first time and want to integrate into my app via the API. I have everything setup and running and have made some successful calls to the API.

When I make the following call, I get XML Parsing Error: not well-formed. It doesn’t like the date being the node name. How can I fix this?

Request: https://piwik.mydomain.com/?token_auth=XXXXXXXXXXX&module=API&method=API.getBulkRequest&format=xml&urls[0]=method=VisitsSummary.get&idSite=all&period=day&date=2013-11-07,2013-11-14&filter_sort_order=asc

Thanks for any help.

if you only have one API, you don’t need to use getBulkRequest instead you can get XML link from: Piwik > API (top menu link) >

Hi Matt,

Thanks for the response. I’m aware that bulk api is used for multiple queries, however, the following will give the same error:

Request: https://piwik.mydomain.com/?token_auth=XXXXXXXXXXX&module=API&method=API.getBulkRequest&format=xml&urls[0]=method=VisitsSummary.get&idSite=all&period=day&date=2013-11-07,2013-11-14&filter_sort_order=asc&urls[1]=method=VisitsSummary.get&idSite=all&period=day&date=2013-11-01,2013-11-07&filter_sort_order=asc

Aside from the question, I wrote a wrapper for my programming language and it uses a global method to send and parse the response into strongly typed objects. In my wrapper, you submit your list of queries, hence why the getBulkRequest was used. Do you have a recommendation or good reason to not use getBulkRequest with only one query?

Also, I noticed the XML is returned and I can see it by viewing the source of the page. Even though the page shows this error:

This page contains the following errors:
error on line 5 at column 5: StartTag: invalid element name
Below is a rendering of the page up to the first error

If I view the source, this is what I see:

<?xml version="1.0" encoding="utf-8" ?> <2013-11-14> 125 318 5 11 25450 0% 28.9 2314 <2013-11-15> 8 11 2 2 592 0% 5.5 296 <2013-11-14> <2013-11-15>

there is indeed a bug iin the bulk XML format.

can you use the JSON format instead? this one should work

Hi Matt,

The json format does indeed work. However, I prefer to work with xml as I find it more pleasurable, especially when using server side languages. I decided to take a look at the source and found that I needed to change the “renderArray($array, $prefixLines)” function inside of the xml data table renderer class and comment out the following lines:

//if (is_numeric($key)) {
$prefix = “<row key=”$key">";
$suffix = “”;
$emptyNode = “<row key=”$key"/>";
//} else {
//$prefix = “<$key>”;
//$suffix = “</$key>”;
//$emptyNode = “<$key />”;
//}

This change results in valid xml and I do not see any side effects to this modification, except for I have to read the key attributes instead of the name, but as far as functionality, it seems to work. Please let me know if you do.

Thank you for the report & patch. I fixed it in API Bulk Requests: invalid output when multiple dates and format is xml · Issue #4313 · matomo-org/matomo · GitHub

Cheers