[Event Rule] saveEventRule with Tradionnal Chinese eventCondition
AnsweredWhen I use System API /ec2/saveEventRule request something with Traditional Chinese content, the Nx Witness UI displays garbled characters.
Just like bellow,
How can I fix this problem?
-
Nx Witness client: 5.1.0.37133(850ab7b33950f)
Server OS: Windows 8.1
Client OS: Windows 10 22H2
Postman for Windows: 10.19.10
Post Body:
{
"id": "{d36561c9-cb35-43fc-abaa-be8f9ffe875c}",
"eventType": "softwareTriggerEvent",
"eventResourceIds": [
"e0c956b9-a035-b064-3410-120db4bccca5"
],
"eventCondition": "{\"caption\":\"GV-AS810-Join測試 - Door 1 - Unlock Door\",\"description\":\"_door_opened\",\"eventTimestampUsec\":\"0\",\"eventType\":\"undefinedEvent\",\"inputPortId\":\"\",\"metadata\":{\"allUsers\":true,\"level\":\"\"},\"omitDbLogging\":false,\"progress\":0,\"reasonCode\":\"none\"}",
"eventState": "undefined",
"actionType": "execHttpRequestAction",
"actionResourceIds": [],
"actionParams": "{\"allUsers\":false,\"authType\":\"authBasicAndDigest\",\"durationMs\":5000,\"forced\":true,\"fps\":10,\"httpMethod\":\"GET\",\"needConfirmation\":false,\"playToClient\":true,\"recordAfter\":0,\"recordBeforeMs\":1000,\"streamQuality\":\"highest\",\"url\":\"http: //192.168.0.228:80/ASWeb/WebService.srf?username=1&password=1&module=monitor&is_nx=1&action=DOOR_OPERATION&operation=UNLOCK_DOOR&dvg_id=0&ctrl_id=1&dr_id=0\",\"useSource\":false,\"gateData\":{\"device_type\":0,\"dvg_id\":0,\"dvg_name\":\"Default\",\"node_id\":1001,\"device_id\":1,\"gate_id\":0,\"io_type\":0,\"device_name\":\"GV-AS810-Join測試\",\"gate_name\":\"Door 1\",\"is_input\":0,\"is_elevator\":0,\"cam_idx\":0,\"nx_cams\":[\"67bb95bd-66dc-f753-c1ba-f399faf82e95\",\"01357f1b-0e0d-e85c-a0a7-e07b816cb748\"]}}",
"disabled":false,
"comment":"ASManager Software Trigger Event",
"system":false
}Body json file: https://drive.google.com/file/d/1yi7McayFcSPolHNZEjYM5uCDjPYosB1h/view?usp=drive_link
Postman collection: https://drive.google.com/file/d/179VH32x3i9AE2q0aDhby6GGDKYpO3O5V/view?usp=drive_link
-
hi,
That seems to be a bug.
The work around would be creating a rule with Chinese symbols in GUI, then requesting the rule via API and copying symbols.
Here is the result for your case
"eventCondition": "{\"caption\":\"GV-AS810-Join 測試 - Door 1 - Unlock Door\",\"description\":\"_door_opened\",\"eventTimestampUsec\":\"0\",\"eventType\":\"undefinedEvent\",\"metadata\":{\"allUsers\":true,\"level\":\"\"},\"omitDbLogging\":false,\"progress\":0,\"reasonCode\":\"none\"}",
-
Hi,
Deeper investigation gave the following solution.
The Server expect latin-1 encoded string representing utf-8 encoded JSON.
That means, before being sent to the Server the JSON has to be
1. serialized
2. encoded to utf-8 byte array
3. byte array has to be decoded to latin-1 string
In python it look like this.
import json
import requests
# omitting authorization requests
event_condition = "{\"caption\":\"GV-AS810-Join測試 - Door 1 - Unlock Door\",\"description\":\"_door_opened\",\"eventTimestampUsec\":\"0\",\"eventType\":\"undefinedEvent\",\"inputPortId\":\"\",\"metadata\":{\"allUsers\":true,\"level\":\"\"},\"omitDbLogging\":false,\"progress\":0,\"reasonCode\":\"none\"}"
rule_json = {
"id": "{d36561c9-cb35-43fc-abaa-be8f9ffe875d}",
"eventType": "softwareTriggerEvent",
"eventResourceIds": [],
"eventCondition" : event_condition.encode("utf_8").decode("latin_1"),
"eventState": "undefined",
"actionType": "execHttpRequestAction",
"actionResourceIds": [],
"actionParams": "{\"allUsers\":false,\"authType\":\"authBasicAndDigest\",\"durationMs\":5000,\"forced\":true,\"fps\":10,\"httpMethod\":\"GET\",\"needConfirmation\":false,\"playToClient\":true,\"recordAfter\":0,\"recordBeforeMs\":1000,\"streamQuality\":\"highest\",\"url\":\"http: //192.168.0.228:80/ASWeb/WebService.srf?username=1&password=1&module=monitor&is_nx=1&action=DOOR_OPERATION&operation=UNLOCK_DOOR&dvg_id=0&ctrl_id=1&dr_id=0\",\"useSource\":false,\"gateData\":{\"device_type\":0,\"dvg_id\":0,\"dvg_name\":\"Default\",\"node_id\":1001,\"device_id\":1,\"gate_id\":0,\"io_type\":0,\"device_name\":\"GV-AS810-Join測試\",\"gate_name\":\"Door 1\",\"is_input\":0,\"is_elevator\":0,\"cam_idx\":0,\"nx_cams\":[\"67bb95bd-66dc-f753-c1ba-f399faf82e95\",\"01357f1b-0e0d-e85c-a0a7-e07b816cb748\"]}}",
"disabled": False,
"comment":"ASManager Software Trigger Event 測試",
"system":False
}
r = requests.post(API_URL,
data=json.dumps(rule_json),
headers={
'Authorization': f'Bearer {bearer_token}',
'Content-Type': 'application/json'
}) -
Please, pay your attention too my post.
https://support.networkoptix.com/hc/en-us/community/posts/18658744103447/comments/19279510380055
I've corrected it. It's not just about UTF-8 encoding.
Please sign in to leave a comment.
Comments
9 comments