How do I create a datasource using the Mango API?
-
Hi,
Swagger shows some details of two API end points that potentially could be used. I'm not sure if I need to PUT to /rest/v1/data-sources/{XID} or POST to /rest/v1/data-sources . I have spent most time trying the PUT option as it is conceptually more appropriate but I get the same result either way.
My attempts have been met with 500 Server Error because I have not uploaded a correctly specified JSON object. I need an explanation of the JSON schema to upload. I tried to create a copy of an existing datasource by uploading the exported JSON for the original with a modified parameter values. The format is not the same as the Swagger documentation specifies so I wasn't surprised I didn't get it to work.
The swagger documentation doesn't make it obvious how to specify that it is a HTTP listener that I wish to create. There are parameters specific to this type that I want to set including IP white list and device ID white list.
Can anyone fill in the gaps please?
Thanks,
Gary
-
Hi Gary,
I think the problem you're experiencing is probably that there was a bug preventing the HTTP Receiver from being created or saved through the API. I fixed this and released a new version of the module, 1.6.2.
If you've got that version, the easiest / best way to get the JSON model is by doing a GET for a data source you've made through the UI. But, here's the JSON for a an HTTP Receiver from my testing:
{ "xid": "httpReceiver2", "name": "HTTP Receiver", "enabled": false, "modelType": "HTTP_RECEIVER", "validationMessages": [], "deviceIdWhiteList": [ "*" ], "setPointUrl": "", "ipWhiteList": [ "*.*.*.*" ], "editPermission": "", "purgeSettings": { "override": false, "frequency": { "periods": 1, "type": "YEARS" } }, "alarmLevels": { "SET_POINT_FAILURE": "URGENT" } }
One must use the POST /rest/v1/data-sources to create data sources, and the PUT /rest/v1/data-sources/[XID] to update existing data sources.
Thanks for bringing that bug to our attention!
-
@phildunlap Thank you. I will give it a try.
-
It works :)
-
Glad to hear it!