Getting a 400 Bad Request error when adding a new event rule for http request as an action using /ec2/saveEventRule API endpint.

Answered

Comments

11 comments

  • Avatar
    Evgeny Balashov

    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

     

    Reference: https://support.networkoptix.com/hc/en-us/articles/115016055728-API-tip-How-to-create-or-modify-Event-Rule

    0
    Comment actions Permalink
  • Avatar
    Usman Asif

    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
    Comment actions Permalink
  • Avatar
    Evgeny Balashov

    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
    Comment actions Permalink
  • Avatar
    Usman Asif

    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
    Comment actions Permalink
  • Avatar
    Usman Asif

    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
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Usman,

    Could you share your code, please?

    0
    Comment actions Permalink
  • Avatar
    Usman Asif

    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
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    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
    Comment actions Permalink
  • Avatar
    Usman Asif

    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
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    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
    Comment actions Permalink
  • Avatar
    Usman Asif

    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
    Comment actions Permalink

Please sign in to leave a comment.