Problem with saveEventRule
CompletedHello,
I am trying to enable and disable an API saveEventRule via http. If I try to send the output of getEventRules only with the changed “eventState”: I always get a “Can't deserialize input Json data to destination object.” error.
But the request is already in square brackets. What am I doing wrong?
-
Ralf,
Upon review of the json text you provided, I do see one glaring discrepancy if the intention was to enable a disabled event rule.
For the "disabled" value you have it still set to "true", while the eventState as you stated was set to "Active".
Please see if you can test with the disabled set to "false" and verify if you still receive the same error.
In the event that you don't have it, our documentation is also very useful to follow around this API call, with specific attention given to the schema part which may help identify potential other reasons for the failure.
You can find that documentation linked HERE.
-
Hello,
when I change the status via the GUI client and compare the variables, the only change is “disabled”: true to false.
But it seems to make no difference what I try to send to the server (version 5.1.4.38659). It always comes back with {
“error”: “2”,
“errorId”: “invalidParameter”,
“errorString”: “Can't deserialize input Json data to destination object.”
}
So there is something fundamentally wrong with the request. It doesn't matter which function I try. -
Hi Ralf Kraemer,
As Michael Palmer mentioned, you may need to check the documentation again.
The saveEventRule API is accepting one single event at a time, your JSON shows a list, so it is not possible for the mediaserver to handle the object correctly.So basically, this error is due to you may send the wrong format in accordance with the API. You may try to remove the [ ] bracket, but only the part of { ... } .
Ex:{
"actionParams": "{\"additionalResources\":[\"{00000000-0000-0000-0000-100000000000}\",\"{00000000-0000-0000-0000-100000000001}\"],\"allUsers\":false,\"authType\":\"authBasicAndDigest\",\"durationMs\":5000,\"forced\":true,\"fps\":10,\"needConfirmation\":false,\"playToClient\":true,\"recordAfter\":0,\"recordBeforeMs\":1000,\"streamQuality\":\"highest\",\"useSource\":false}",
"actionResourceIds": [],
"actionType": "showPopupAction",
"aggregationPeriod": 60,
"comment": "Test",
"disabled": true,
"eventCondition": "{\"analyticsEngineId\":\"{1e5613c4-b7ac-546d-6623-8c179de18114}\",\"eventTimestampUsec\":\"0\",\"eventType\":\"undefinedEvent\",\"inputPortId\":\"nx.hikvision.Motion\",\"metadata\":{\"allUsers\":false,\"level\":\"\"},\"omitDbLogging\":false,\"progress\":0,\"reasonCode\":\"none\"}",
"eventResourceIds": [
"{5200d26b-84c4-7797-dc34-5062756e1932}"
],
"eventState": "Active",
"eventType": "analyticsSdkEvent",
"id": "{2a2a8ec6-1123-4ac4-af68-89687de2a126}",
"schedule": "",
"system": false
} -
This is driving me mad...
Even if im am trying to simplify the request to the minimum mandatory api Settings:
{"actionResourceIds": [],"actionType": "showPopupAction","aggregationPeriod": 60,"comment": "Test","disabled": true,"eventResourceIds": ["{b57f033b-0155-d788-c214-f2964218f72a}"],"eventState": "Active","eventType": "analyticsSdkEvent","id": "{ddb2cf95-cdfc-4e19-8eb7-687d36ef34e0}","schedule": "","system": false}it fails with:{
"error": "2",
"errorId": "invalidParameter",
"errorString": "Can't deserialize input Json data to destination object."
} -
Unofficially: to enable / disable a rule via API, you only need the ID & disabled state in the JSON data, not all the other guff ;-)
-
Hi Ralf Kraemer,
It is great to hear that you have a solution. Here are some more notices from Andrew's comment.
1. You can send the JSON which contains at least one first level node, ex : eventState, aggregationPeriod, enabled...etc. So if you are really sure you just need to change the value of "enabled", this could be a solution for you. However, sending a full list will never go wrong.
2. The JSON you provided is likely needs to be corrected, as you provide "empty" value in the "actionResourceIds": []", but you requested the action to be a "showPopupAction of Resources".
Considering this is an event that would popout some videos, you can't assign null for this action. This would be the same while you operate the desktop client. You have to assign the targeted resource of the actions to fit your own configurations. This is basically how the API and event settings which are required to be done.3. If you check it in your content, it is likely not the spaces, but the encoded text of space or EOL symbols or others. Different text encoding sets might have different presentation of the symbols or spaces, EOL symbols usually not being shown on the screen, so you may think that is a space.
Nx Witness uses and supports UTF-8, I sincerely suggest you can check if your text is in UTF-8. (This unexpected case usually happens while using Windows,or copy and paste from web browser with default locale and encoding and formatting, ex: Big5, ASCII, automatical layout arrangement...etc)
Ex: you can see the "non-breaking-space" while I copied my reply from the webpages.
Hope this helps.
-
Ralf Kraemer, Ichiro,
We found a bug in VMS API Documentation testing tool:Whenever JSON in request contains a JSON as a string value (like in case of Event Rules actionParams and eventCondition) the api tool corrupts values and make request incorrect. We're going to fix it in the in one of the upcoming patches. It does not affect VMS API functionality though, if you try to send such requests via PostMan or python they should work normally.
Also, as Ichiro pointed out, our testing tool does not show all of the UTF-8 characters which can also break the request and our legacy API (which is the only option for Event Rules now) does not report request parsing errors correctly. We're already working on a replacement API for Event Rules but it's likely take a couple of more releases. For now we're investigating a possibility to visualize request errors in the testing tool though.
Please sign in to leave a comment.
Comments
8 comments