Basic C# API Interface

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
Glyphs
Posts: 3
Joined: Fri Mar 18, 2016 2:32 pm

Basic C# API Interface

Post by Glyphs »

Hello, I figured I'd share this with people that might at some point have a use for it: https://source.vanharberden.eu/silvester/zoneminder-api (NOTE: HTTPS Check-Out is broken due to the system being behind a reverse proxy, please use SSH checkout instead.)

It's a fairly simple class library that lets you retrieve data from your ZoneMinder system. So far it contains stuff I had a need for when writing an application, but since the application is no longer a necessity it has more or less turned into my little playground. Currently it does not allow you to SET data, it only retrieves data.

It's fairly simple to use, I've got some examples here:

Code: Select all

void Main() {
	var zm = "https://yourinstallhere/zm";
	var zmapi 	= "https://yourinstallhere/zm/api";
	var user = "user";
	var pass = "password";
	
	// Stop webrequests from throwing SSL errors. Only use it on self-signed certificates.
	//ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return true; };

	using (var controller = new ZoneMinderController(zm, zmapi, user, pass)) {
		// If we're not authenticated, don't bother retrieving our data.
		if (!controller.Authenticate()) return;
		
		// retrieve a list of all Monitors.
		var monitors = controller.GetMonitors();
		
		// Retrieve a list of all events.
		var events = controller.GetEvents();
		
		// Retrieve our latest event and all of its information, including frames.
		var eventid = controller.GetPageEvents(controller.GetPageCount()).OrderByDescending(c => c.Id).First().Id;
		var eventframes = controller.GetFrames(eventid);
               var eventdata = controller.GetEventData(eventid);

		// Or events during a specific timeframe.
		var rangeevents = controller.GetEvents(DateTime.Today.AddDays(-7), DateTime.Now) select e);
	}	
}
There's a good couple of overloads on most methods, so you can finetune the results pretty well.

I'll likely be tinkering some more, and adding more stuff to it. I've already scrapped some ideas I had because they either didn't work or weren't feasible.. But if you want anything specific in it just let me know, I'll see what I can do. Note that it does not support (Re)Captcha, I have ways of dealing with Captcha, but ReCaptcha is just a major pain in the behind.
Last edited by Glyphs on Wed May 18, 2016 10:02 am, edited 1 time in total.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Basic C# API Interface

Post by asker »

Nice job!
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Glyphs
Posts: 3
Joined: Fri Mar 18, 2016 2:32 pm

Re: Basic C# API Interface

Post by Glyphs »

I've moved the repository to my own personal machine: https://source.vanharberden.eu/silvester/zoneminder-api (NOTE: HTTPS Check-Out is broken due to the system being behind a reverse proxy, please use SSH checkout instead. For some reason GitLab has not implemented a method to disable HTTPS cloning yet.)

Also added the ability to delete events and monitors. Might work on being able to edit and add monitors, but since I have no use for that at the present time I can't make any promises.
ismayandi
Posts: 2
Joined: Mon Oct 29, 2018 6:48 am

Re: Basic C# API Interface

Post by ismayandi »

Hello,

firstly i'm sorry that i brought this old post back. but can't find any post that match my project needs. Recently my boss need to access a camera remotely from my project (which is a WPF C# project). He had installed ZoneMinder Server. So i need an interface to access the server, precisely what @Glyphs doing. I had follow the link, but the project seems to be missing or deleted or maybe a private. Can anyone lead me to any other similar API.

Thanks.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Basic C# API Interface

Post by asker »

Why not just write your own wrapper over the existing ZM APIs?
https://zoneminder.readthedocs.io/en/stable/api.html
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
ismayandi
Posts: 2
Joined: Mon Oct 29, 2018 6:48 am

Re: Basic C# API Interface

Post by ismayandi »

asker wrote: Thu Nov 01, 2018 4:31 pm Why not just write your own wrapper over the existing ZM APIs?
https://zoneminder.readthedocs.io/en/stable/api.html
Yeah, thats what i'm trying now. but i'm stuck in the first try already. i try to get monitors using remote PC to the zm server, but it returns "Page Not Found" like this :

curl: (6) Could not resolve host: curl
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /zm/api/monitors.json was not found on this server.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at 192.168.1.4 Port 80</address>
</body></html>

please guide me, i'm completely newby to this.

thanks before.
alabamatoy
Posts: 360
Joined: Sun Jun 05, 2016 2:53 pm

Re: Basic C# API Interface

Post by alabamatoy »

ismayandi wrote: Mon Nov 05, 2018 8:56 am Yeah, thats what i'm trying now. but i'm stuck in the first try already. i try to get monitors using remote PC to the zm server, but it returns "Page Not Found" like this :
I would look first to the zoneminder configuration, and make sure the API is enabled. Console, options, system, enable zoneminder APIs checkbox. May need to restart to fully enable. The 404 not found error is coming from the webserver, so its not even finding the APIs.
Post Reply