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

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: 950
Joined: Sun Mar 01, 2015 12:12 pm

Re: Basic C# API Interface

Post by asker » Sat Mar 26, 2016 8:17 pm

Nice job!
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

Glyphs
Posts: 3
Joined: Fri Mar 18, 2016 2:32 pm

Re: Basic C# API Interface

Post by Glyphs » Wed May 18, 2016 10:04 am

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

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: 950
Joined: Sun Mar 01, 2015 12:12 pm

Re: Basic C# API Interface

Post by asker » 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
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

ismayandi
Posts: 2
Joined: Mon Oct 29, 2018 6:48 am

Re: Basic C# API Interface

Post by ismayandi » Mon Nov 05, 2018 8:56 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests