Cumulocity-IoT / cumulocity-python-api

Python client for the Cumulocity REST API. Created by Global Competency Center IoT
Apache License 2.0
18 stars 13 forks source link

Alarm with None time attribute returns an error #14

Closed PestusAtSAG closed 2 years ago

PestusAtSAG commented 2 years ago

Following alarm results in an exception: alarm = Alarm(None, 'sag_DobotAlarm', None, deviceId, text, Alarm.Status.ACTIVE, Alarm.Severity.MAJOR)

File "C:\Users\APES\AppData\Local\Programs\Python\Python310\lib\site-packages\c8y_api\model\alarms.py", line 333, in create super()._create(Alarm.to_full_json, *alarms) File "C:\Users\APES\AppData\Local\Programs\Python\Python310\lib\site-packages\c8y_api\model_base.py", line 494, in _create self.c8y.post(self.resource, json=jsonify_func(o), accept=None) File "C:\Users\APES\AppData\Local\Programs\Python\Python310\lib\site-packages\c8y_api_base_api.py", line 190, in post raise ValueError(f"Unable to perform POST request. Status: {r.status_code} Response:\n" + r.text) ValueError: Unable to perform POST request. Status: 422 Response: {"error":"undefined/validationError","message":"Following mandatory fields should be included: time","info":"https://www.cumulocity.com/guides/reference-guide/#a-name-error-reporting-a-error-reporting"}

Using now() is working fine: alarm = Alarm(None, 'sag_DobotAlarm', datetime.now().isoformat(), deviceId, text, Alarm.Status.ACTIVE, Alarm.Severity.MAJOR)

chisou commented 2 years ago

Not an API error, because this is caused by Cumulocity backend. But it would be a nice feature to have without diverting from the API concept.

chisou commented 2 years ago

I've updated to API to accept time='now for both Event and Alarm. This is more explicit that leaving it blank and still handy enough I think. This is part of version 1.2.