Page 1 of 1

API: Can someone tell me why this doesn't work?

Posted: Wed Feb 17, 2016 8:43 pm
by StNick
I want to get a list of all the frames from a specific event (#711) using the API. According to the docs (and REST), I am pretty sure this should work:

Code: Select all

http://localhost/zm/api/frames/index/EventId:711.json
However, this is returning every frame without any filtering at all.

Re: API: Can someone tell me why this doesn't work?

Posted: Thu Feb 18, 2016 7:02 am
by Tantamount
Lol, when I tried that I got this:

Code: Select all

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /usr/share/zoneminder/www/api/lib/Cake/Model/Datasource/Database/Mysql.php on line 274
So, yeah, it's returning all the frames in the entire database.

No matter what I tried after index/ the system would ignore it and return everything.

1.29.0

Re: API: Can someone tell me why this doesn't work?

Posted: Thu Feb 18, 2016 3:37 pm
by asker

Code: Select all

http://localhost/zm/api/events/711.json

Re: API: Can someone tell me why this doesn't work?

Posted: Fri Feb 19, 2016 7:18 am
by StNick
asker wrote:

Code: Select all

http://localhost/zm/api/events/711.json
Yeah this works, but it returns the entire event, including non-frame information I am not interested in. I'm really more curious as to why the specific API call isn't working as expected. Could be a bug.

Re: API: Can someone tell me why this doesn't work?

Posted: Fri Feb 19, 2016 1:19 pm
by asker
StNick wrote:
asker wrote:

Code: Select all

http://localhost/zm/api/events/711.json
Yeah this works, but it returns the entire event, including non-frame information I am not interested in. I'm really more curious as to why the specific API call isn't working as expected. Could be a bug.
Could you point me to where you found the Frame API you were trying earlier ? I did not find it in https://zoneminder.readthedocs.org/en/stable/api.html

I don't recommend using the Frame API - if you look at
https://github.com/ZoneMinder/ZoneMinde ... roller.php
there are no limits anywhere and even a small install can overwhelm the DB with this API - that is also the reason why I did not document it, so I'm curious where you found that construct.

Re: API: Can someone tell me why this doesn't work?

Posted: Sat Feb 20, 2016 6:06 am
by StNick
The documentation does not provide a full breakdown of all method constructs; merely a number of "examples" as it calls them. In my original post, I was making the assumption that the Frame construct followed the same pattern as the Event construct, for which an example was provided.

Thank you for the reply and clarification on the limitations of the Frame API, however. I will continue to use the other method mentioned above.

Re: API: Can someone tell me why this doesn't work?

Posted: Sun Feb 21, 2016 1:53 am
by Tantamount
asker,

The docs state:
The API is built in CakePHP and lives under the /api directory. It provides a RESTful service and supports CRUD (create, retrieve, update, delete) functions for Monitors, Events, Frames, Zones and Config.
Since it states "Frames" is already supposed to be part of the API, and since the docs only provide a limited number of examples, it's not unreasonable to expect calls that work with Events to work the same with Frames.

What is the state of the API? Is it supposed to be feature complete? I ask only to know if we should be reporting bugs yet or not.

Re: API: Can someone tell me why this doesn't work?

Posted: Sun Feb 21, 2016 1:35 pm
by asker
So here is the story with the APIs. The original developer is Kyle Johnson - he's the guy who knows PHP/Cake and the rest. It was partially developed and then parked because he did not have the time to continue. Last year, when I started developing zmNinja, I thought it would be good to base in on APIs instead of skin-scraping. So I took over the API development and extended it mostly to make it work for zmNinja (Which meant learning whatever I could of PHP and cakePHP to make things works).

So the APIs should not be considered as feature complete. They have not been tested for load/overflow and other conditions. Please don't expect anything to work correctly that has not been explicitly documented. And I'm very open to others contributing code - especially those who know PHP/Cake and/or want to learn.

I know for example the Frames API don't work (and also know why - the frames DB is the largest DB in ZM - doing an unbounded seek there is bound to overwhelm), I started a PR for honoring user roles --> till a few months ago, the APIs would report all monitors/events/etc to any ZM user - irrespective of their permissions in ZM. I have a partial PR merged that somewhat honors roles, but I know it still returns data in certain cases that it should not https://github.com/ZoneMinder/ZoneMinder/issues/1155

etc etc

So feel free to post API issues, but I'm also more interested in folks who can works towards fixing them (given my sparse knowledge and time). If you do post API issues, I'll get to fixing them, but can't guarantee when.

Hope this answers.
thx

Tantamount wrote:asker,

The docs state:
The API is built in CakePHP and lives under the /api directory. It provides a RESTful service and supports CRUD (create, retrieve, update, delete) functions for Monitors, Events, Frames, Zones and Config.
Since it states "Frames" is already supposed to be part of the API, and since the docs only provide a limited number of examples, it's not unreasonable to expect calls that work with Events to work the same with Frames.

What is the state of the API? Is it supposed to be feature complete? I ask only to know if we should be reporting bugs yet or not.

Re: API: Can someone tell me why this doesn't work?

Posted: Sun Feb 21, 2016 1:42 pm
by StNick
Thanks for the update, and your work thus far; it is appreciated.

Re: API: Can someone tell me why this doesn't work?

Posted: Tue Feb 23, 2016 6:42 am
by Tantamount
Thanks for the background info asker, and for breathing new life into the API.

It's not even funny how many frameworks there are for php now. I wonder why cakePHP was chosen.