Page 1 of 1

Basic C# API Interface

Posted: Fri Mar 18, 2016 2:49 pm
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.

Re: Basic C# API Interface

Posted: Sat Mar 26, 2016 8:17 pm
by asker
Nice job!

Re: Basic C# API Interface

Posted: Wed May 18, 2016 10:04 am
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.

Re: Basic C# API Interface

Posted: Mon Oct 29, 2018 7:20 am
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.

Re: Basic C# API Interface

Posted: Thu Nov 01, 2018 4:31 pm
by asker
Why not just write your own wrapper over the existing ZM APIs?
https://zoneminder.readthedocs.io/en/stable/api.html

Re: Basic C# API Interface

Posted: Mon Nov 05, 2018 8:56 am
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.

Re: Basic C# API Interface

Posted: Mon Jan 14, 2019 7:07 pm
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.