Add new rules by API in MPI - (C#)

I am try to create new rule(to start and stop recording) by API post request and i get 400 bad request with response :

(i am try it in postmen)

{

“params”:{

“name” :“myEvent”,

“description”: “”,

“startRuleType”: “Event”,

“startEventGroup”:“”

}

}

my request details:

POST REQUEST

URL : http://{my server name}/api/rest/v1/rules

AUTHORIZATIONS: bearerAuth

BODY:

{

“enabled”: true,

“name”: “myEvent”,

“description”: “”,

“startRuleType”: “Event”,

“stopRuleType”: “Event”,

“always”: false,

“withinTimeProfile”: false,

“outsideTimeProfile”: false,

“timeOfDayBetween”: false,

“daysOfWeek”: false,

“failoverActive”: false,

“failoverInactive”: false,

“startActions”: “StartRecording;StartFeed”,

“stopActions”: “StopRecording;StopFeed”

}

Would love your help.

thanks.

The documentation for this is here. https://doc.developer.milestonesys.com/mipvmsapi/api/config-rest/v1/#tag/Rule/operation/getAllrules

My guess is that you are aware and have been consulting the documentation.

I have a suggestion. Try to make a rule in the Management Client that is exactly what you need. Then in Postman read the rule as first step (GET). Try to use the response, with only minimal change, say only change name, to do a new new rule (POST). This way I have an idea that you can detect if there are subtle things about the types or other parameters that are not apparent from reading the documentation.

I believe that the 400- Bad request and response body is saying that when you have “startRuleType”: “Event” you need to supply additional parameter “startEventGroup” (or more). As this is not in the documentation as far as I can see I hope you can use my suggestion to get a better glimpse of what is needed.

Ok, I used your suggestion, I was able to create a new rule.

only one thing I’m missing, where can I get this parameter:

“startEventSources” : [

"type":"external",

 "id": "XXX"

]

(I expect another HTTP call to return the ID)

I tried to search your documentation without success :frowning:

User defined events are a bit special, a lot of events also have a source like a camera event that happens on a camera has the camera as source. In user defined events it is just the event in itself. So there is an explanation here in documentation for Rules in the configuration API..

https://doc.developer.milestonesys.com/html/index.html?base=gettingstarted/intro_configurationapi.html&tree=tree_search.html?search=e8bd6cee

You might ask why Configuration API? The Configuration API and the Rest API have a lot in common, and general information for one will often fit the other. It is not ideal that there isn’t the same information in the Rest API documentation and I will try to flag it so that the documentation might get improved in a future version.

It works! Thank you