How to trigger event to request a stop/start recording of cameras through web API ?

In my company, we have several web application to centralize data/event from business.

We would like to use our owner web api to start/stop the camera recording.

I found this documentation: Milestone XProtect Events API Reference

And this forum: How to start/stop camera recording using Milestone ServerCommandService SOAP protocol?

So normally, it’s possible to trigger the event RequestStartRecording through the web API to start the camera recoding… For that, I need the event type id, data type (=free-form) and a data to list camera id list.

Example script (in powershell for PoC):

$token="Bearer xxxxxxxxxxxxx"
$cameraId="xxxx-xxxx-xxxx-xxxx"
$RequestStopRecordingId="yyyyy-yyyy-yyyy-yyyy"
 
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $token)
$headers.Add("Content-Type", "application/x-www-form-urlencoded")
 
$body = @{
    type=$RequestStopRecordingId
    source=$null
    datatype="free-form"
    tag=$null
    data= @{
        TargetDevices="
        <targetDevices>
            <deviceIds>
                <deviceId>$($cameraId)</deviceId>
            </deviceIds>
            <deviceGroupsIds />
        </targetDevices>
        "
    }
}
$response = Invoke-RestMethod "http://<myserver>/api/rest/v1/events" -Method 'POST' -Headers $headers -Body $body
echo $(response | ConvertTo-Json)

When i run my script, I received a 400 response (BAD Request) and I think that come from the “data” attribut.

I’m not able to find any more information about the JSON structure required to trigger RequestStartRecording/RequestStopRecording event.

Could you please help me ?

I think and hope this fits:

https://developer.milestonesys.com/s/question/0D5bH00001JQFiPSAX/start-recording