Getting a 400 Bad Request error when adding a new event rule for http request as an action using /ec2/saveEventRule API endpint.
AnsweredI am trying to create an event rule to get information about motion detection events when they occur on my server. I am using /ec2/saveEventRule POST API endpoint to save that rule but I am getting 400 Bad Request in response and there is no explanation where the issue is.
What I need is that whenever a motion detection event occurs, I should get a hit on my server on a route with it's system_id, camera_id and time of the event. Here is the json that I am sending:
{
"id": "{846c9aec-229d-4b1d-91ac-4bb14b763457}",
"eventType": "cameraMotionEvent",
"eventState": "active",
"actionType": "cameraOutputAction",
"disabled": "false"
}
I have added all the fields that are required according to the documentation but I am still getting 400 status in response. Let me know what I need to update for it to work properly?
Also do I need to create an event rule for each camera in a system or one event per system would work for each camera as well?
I also need to know in which field should I add the http url to for my server?
-
Try doing this:
1. Create a rule manually using the desktop application
2. Retrieve the rule from the server using API
3. Use this JSON as a template for future requests
0 -
I copied the exact json object from the getEventRules API endpoint that I created manually with the exception of the id. I updated the id that I have created according the https://support.networkoptix.com/hc/en-us/articles/115016055728-API-tip-How-to-create-or-modify-Event-Rule. Now I am getting 403 error.
0 -
403 most likely means that user doesn't have admin credentials to create/modify the rule. Can you check that?
Also, what is the response body? It might have additional information about the error
0 -
I am using the same credentials to create the rule using the API that I used in the desktop application. And as for the response body there is no body, there is only a status in case of an error.
0 -
There is an other issue that I am seeing is that the rule I created using the desktop app (eventType = cameraMotionEvent) is just keep on hitting the http url every 10 seconds with nothing in the body at all.
0 -
Hello Usman,
Could you share your code, please?
0 -
I have managed to get it working, thank you for your help. But the issue of rule hitting the http end point after a few seconds is still there and it is sending no information about the event.
Do I have to add hardcoded values in the http content section or is there a way to get dynamic values in the http content?
Here is the json that I sent to saveEventRule:
{
"actionParams": "{\"allUsers\":false,\"authType\":\"authBasicAndDigest\",\"contentType\":\"application/json\",\"durationMs\":5000,\"forced\":true,\"fps\":10,\"needConfirmation\":false,\"playToClient\":true,\"recordAfter\":0,\"recordBeforeMs\":1000,\"requestType\":\"\",\"streamQuality\":\"highest\",\"url\":\"https://:@14b8ad82e305.ngrok.io/nx/motion_event\",\"useSource\":false}",
"actionType": "execHttpRequestAction",
"aggregationPeriod": 60,
"comment": "",
"disabled": False,
"eventCondition": "{\"eventTimestampUsec\":\"0\",\"eventType\":\"undefinedEvent\",\"metadata\":{\"allUsers\":false,\"level\":\"0\"},\"omitDbLogging\":false,\"reasonCode\":\"none\"}",
"eventResourceIds": [],
"eventState": "Active",
"eventType": "cameraMotionEvent",
"id": "{846c9aec-229d-4b1d-91ac-4bb14b763457}",
"schedule": "",
"system": False
}0 -
Hi Usman,
> But the issue of rule hitting the http end point after a few seconds is still there and it is sending no information about the event.
I guess, these threads are worth reading and might be helpful
https://support.networkoptix.com/hc/en-us/community/posts/360042988034-How-to-use-execHttpRequestAction-and-it-complete-functionality
https://support.networkoptix.com/hc/en-us/community/posts/360043924814/comments/360011341914
https://support.networkoptix.com/hc/en-us/community/posts/360042150894-How-create-Event-through-APIs-and-execute-them-Please, let us know if it helps.
0 -
Hi Andrey,
I have tried setting the http content like this:
{
"camera_id": {event.cameraId},
"description": {event.description},
"system_id": "2d6eea54-bf82-428d-971e-f22169ef8848"
}
But instead of getting a value for a camera id in camera_id I get the text {event.cameraId}.
I also tried to sent it as a url params like: https://mysite.com/events?cameraId={event.cameraId}. But still I get the text {event.cameraId} instead of a value.
I have tried the documentation and a few other things but I am unable to get a value for camera id in the http request. Let me know if there is a way to do this or would I have to do this manually?
0 -
Hello Usman,
It is totally unclear a part of which function is the JSON you shared:
{
"camera_id": {event.cameraId},
"description": {event.description},
"system_id": "2d6eea54-bf82-428d-971e-f22169ef8848"
}Could you please specify what exactly are you doing? Where do you place this json?
If you are configuring a rule, could you share a screenshot showing rule settings?> But instead of getting a value for a camera id in camera_id I get the text {event.cameraId}.
Where do you get these results?
0 -
Hi Andrey,
Thank you for taking the time to get back to me but I have completed my task by using a different approach.
I added the json and other variation for it in the same place as of this person https://support.networkoptix.com/hc/en-us/community/posts/360043924814-Push-Notifications-and-Event-Rules-Variables-for-HTTP-Post-Event?page=1#community_comment_360011341914 . I needed the camera id in the http request when an event occurs.
Thank you again for your time and help.
0
Please sign in to leave a comment.
Comments
11 comments