Skip to content
Rello edited this page Aug 25, 2020 · 23 revisions

Analytics features a REST API to update data from external applications.

This only applies to reports of type "Internal Database"

  1. create an application password for the api connection in user->setting->security
  2. use the endpoint .../nextcloud/apps/analytics/api/1.0/adddata/{datasetId}
  3. use the POST method
  4. provide the parameters

V1.0

add data

Add one data record to a dataset

endpoint:

  • /nextcloud/apps/analytics/api/1.0/adddata/{datasetId}

data format:

  • {"dimension1": "x", "dimension2": "x", "dimension3": "333,3"}

V2.0

add data

Add one or many data records. All records need to be surrounded in [] - this is different to V1.0

endpoint:

  • /nextcloud/apps/analytics/api/2.0/adddata/{datasetId}

data format:

  • [{"..": "x", "..": "y", "..": "1,1"},{...}]
  • parameters have to be named like set up in the dataset definition with there display names (e.g. 'Column 1', 'Average Value")

remove data

Remove existing data from a dataset

endpoint:

  • ...

data format:

  • ...

Example CURL:

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

Example python:

user = 'user' passw = 'password' headers = {'Content-Type': 'application/json'} url = 'http://xxx/nextcloud/apps/analytics/api/1.0/adddata/' + '20' now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') payload = {'dimension1': sensor, 'dimension2': now, 'dimension3': value} r = requests.post(url, json=payload, headers=headers, auth=(user, passw))


Error Codes

  • UNKNOWN = 9001
  • MISSING_PARAM = 9002
  • NOT_FOUND = 9003
  • NOT_ALLOWED = 9004

Clone this wiki locally