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

Forum for questions and support relating to the 1.29.x releases only.
Locked
StNick
Posts: 6
Joined: Tue Feb 16, 2016 5:17 pm

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

Post 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.
Tantamount
Posts: 76
Joined: Wed Feb 03, 2016 7:51 am

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

Post 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
3 ReoLink RLC-410
2 Annke NC800
Kubernetes 1.22.6 statefulset of 5 Ubuntu 20.04 pods using iconnor's repository
ZoneMinder Version 1.36.12
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

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

Post by asker »

Code: Select all

http://localhost/zm/api/events/711.json
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
StNick
Posts: 6
Joined: Tue Feb 16, 2016 5:17 pm

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

Post 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.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

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

Post 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.
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
StNick
Posts: 6
Joined: Tue Feb 16, 2016 5:17 pm

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

Post 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.
Tantamount
Posts: 76
Joined: Wed Feb 03, 2016 7:51 am

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

Post 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.
3 ReoLink RLC-410
2 Annke NC800
Kubernetes 1.22.6 statefulset of 5 Ubuntu 20.04 pods using iconnor's repository
ZoneMinder Version 1.36.12
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

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

Post 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.
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
StNick
Posts: 6
Joined: Tue Feb 16, 2016 5:17 pm

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

Post by StNick »

Thanks for the update, and your work thus far; it is appreciated.
Tantamount
Posts: 76
Joined: Wed Feb 03, 2016 7:51 am

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

Post 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.
3 ReoLink RLC-410
2 Annke NC800
Kubernetes 1.22.6 statefulset of 5 Ubuntu 20.04 pods using iconnor's repository
ZoneMinder Version 1.36.12
Locked