Rest API, CURL problem

Nextcloud version (eg, 18.0.3):
Operating system and version (Ubuntu 18.04.03):
Apache or nginx version (Apache 2.4.):
PHP version (7.3):

Hi,

really interesting app for data! However, I am struggling with sending data over the Rest API. I have read the documentation and also watched the video about it but even I send the data, no data appear in the “report”.

The report is reporting this url to Rest API: /index.php/apps/analytics/api/1.0/adddata/4
The documentation features this example:

curl -u user:password -d '{"dimension1": "x", "dimension2": "x", "dimension3": "333,3"}' -X POST -H "Content-Type: application/json" http://***/nextcloud/apps/analytics/api/1.0/adddata/10

My call is therefore like this:

curl -u admin:**** --data @data.json -X POST -H "Content-Type: application/json" http://****.com/index.php/apps/analytics/api/1.0/adddata/4

Where data.json looks like:

{
  "dimension1":"10002",
  "dimension2":"12",
  "dimension3":"10002"
}

This will result into this after running via Windows 10:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://****.com/index.php/apps/analytics/api/1.0/adddata/4">here</a>.</p>
</body></html>

No data added or any change to the report. I am already lost in this, tried different combinations but without any result. Any idea what I am doing wrong?

thx, Tomas

Okey, I am stupid like hell :slight_smile: the .htaccess was blocking the call…jeez.

Tomas

Hello,
nice to hear that it is solved. because from first sight all looked good.

data looks as expected in the report?

Hi Rello,

the issue was quite simple to solve but it really took me some time to realize where is the catch :slight_smile:

The data looks great, I am really happy about that. The only issue I have found is sorting of the data while using the “date in the second column” chart. The chart is sorting the dates right but when it comes for example to: 20.04.2020 1:10:10 followed by 20.04.2020 10:10:10, it will place the 10:10:10 record in front of the 1:10:10. I had to format the timestamp to always be hh:mm:ss, otherwise it will not work properly.

Tomas

hello,
yes, that the standard date sorting. good that you could adjust it - because adjusting the chart would not be that easy

hi,
ok, i get your point about the sorting. I was confusing the “line” chart for a “scatter” type - dont know why :slight_smile: . Now it makes a perfect sense.

Do you think the “scatter” option will be available for the analytics in the future? Any workaround of how to plot x-y data currently?

best regards, Tomas

Hello,
I can add it with the next release. does not sound too complicated. will check

Hi, that would be great!
Speaking about possible “add-ons”, from the user experience I had so far I missing these options/features there. Not sure if it is possible to do but I will mention it anyway :slight_smile:

Sharing: The share options are very limited and for example there is no way to share the “charts” between the users of the same Nextcloud instance. The only possible way is a “share link”. I would be great to have the option to share the “charts” between the users without the need of a “direct link”.

Chart options: The chart options are now allowing to control some options of the chart but for example “pointstyle” is not possible to change/add because it is a part of the “datasets” settings and not “options” - at least I didnt find a way. It would be great to have the option to add these settings the same way as the “options”.

great job anyway! thank you for this and best regards, Tomas

Hello @Rello ,
I have similar problem.
When I call:

curl -u user:pass -d '{"data":[{"dimension1": "x", "dimension2": "y", "dimension3": "333,3"}]}' -X POST -H "Content-Type: application/json" http://***.de/index.php/apps/analytics/api/3.0/data/4/add

I am getting following answer:

!DOCTYPE HTML PUBLIC “-//IETF//DTD HTML 2.0//EN”>

404 Not Found

Not Found

The requested URL was not found on this server.


Apache/2.4.41 (Ubuntu) Server at ***.de Port 80

Any ideas?

Thank you!

I think there is an error in the url. Test the url in a browser to verify.

Hello @devnull ,
thank you for your feedback.
When I put this URL into Webbrowser on my PC, it is being automatically forwarded to my Nextcloud homepage (Dashboard). When I do the same on my phone, I get the message that the Website is not working. I just see that in both cases http:// is being automatically changed into https://.

This is what I am getting from Analytics:

image

In all the tutorials I found, there is /nextcloud/ instead of /index.php/. But none of these works for me.

Thank you!

I think I found the problem.

In

/etc/apache2/sites-enabled/000-default.conf

I have changed

DocumentRoot /var/www/html

to

DocumentRoot /var/www/nextcloud

Then for this call:

curl -u user:pass-d ‘{“data”:[{“dimension1”: “x”, “dimension2”: “y”, “dimension3”: “333,3”}]}’ -X POST -H “Content-Type: application/json” http://my_domain.de/index.php/apps/analytics/api/3.0/data/4/add

I got following response:

{“success”:false,“error”:{“code”:9002,“message”:“value required”}}

Solution: “dimension3” has to be changed with “value”.

Hello @dbarackov

correct. you have to either use the technical names of the structure or your own given names.

{"dimension1": "x", "dimension2": "y", "value": "1,1" }

or e.g.
{ "Column 1": "x", "Free Text": "y", "Percentage": "12" }