Page 1 of 1

[Solved] v1.37.1 API - enabling issue (zmninja app on iPhone)

Posted: Fri Oct 29, 2021 10:45 am
by lyallp
For some reason, the API does not seem to work for me.
I have tried following instructions from various places, including downloading 'crud' and copying it into the ZM web tree.

Code: Select all

curl -XPOST -d "user=admin&pass=blah" http://localhost/zm/api/host/getVersion.json
404, not found.
I have gone looking for 'getVersion.json', in the ZM web tree, it does not exist.
I have tried looking for *.json, in the ZM web tree

Code: Select all

# pwd
/usr/share/zoneminder/www
root@Lyalls-PC www
# find . -name '*.json' -print
./vendor/ircmaxell/password-compat/composer.json
./vendor/firebase/php-jwt/composer.json
./vendor/composer/installed.json
./api/app/vendor/composer/installers/composer.json
./api/app/vendor/composer/installed.json
./api/app/Plugin/CakePHP-Enum-Behavior/composer.json
./api/app/Plugin/Crud/composer.json
./api/composer.json
./skins/classic/js/jquery-ui-1.12.1/package.json
root@Lyalls-PC www
# 
I tried downloading the source of ZoneMinder from git.

Code: Select all

root@Lyalls-PC www
# cd /tmp/zoneminder-master/
root@Lyalls-PC zoneminder-master
# find . -name '*.json' -print
./web/vendor/ircmaxell/password-compat/composer.json
./web/vendor/firebase/php-jwt/composer.json
./web/vendor/composer/installed.json
./web/skins/classic/js/jquery-ui-1.12.1/package.json
./web/composer.json
./web/api/composer.json
./web/api/app/vendor/composer/installers/composer.json
./web/api/app/vendor/composer/installed.json
root@Lyalls-PC zoneminder-master
# 
Is it because the doc is wrong or has the API fallen by the wayside somewhere?

Re: v1.37.1 API - enabling issue (zmninja app on iPhone)

Posted: Fri Oct 29, 2021 1:16 pm
by Magic919
It's an API call and doesn't exist on the filesystem.

Re: v1.37.1 API - enabling issue (zmninja app on iPhone)

Posted: Sat Oct 30, 2021 2:48 am
by lyallp
I follow https://zoneminder.readthedocs.io/en/latest/api.html
No results. I actually get an Apache 404 error when I try do the login.json step.

There are no url rewrites in the apache configuration for zoneminder.

The Apache web server must have something to serve.

There is nothing under the api directory called host.

There are no .htaccess files that rewrite urls, so that doesn't help.

Stating that just because it's an API that nothing exists on the filesystem is nonsensical.

You have to have something to serve to process the API requests.

Re: v1.37.1 API - enabling issue (zmninja app on iPhone)

Posted: Sat Oct 30, 2021 6:48 am
by Magic919
I’m sure you appreciate that something.json is just a payload returned by the API in response to a call.

I’ll leave you to it.

Re: v1.37.1 API - enabling issue (zmninja app on iPhone)

Posted: Sat Oct 30, 2021 11:54 am
by lyallp
Thanks, 35 years in the computing industry, I think I'd know what an API is.

Re: v1.37.1 API - enabling issue (zmninja app on iPhone)

Posted: Sat Oct 30, 2021 2:36 pm
by asker
Umm, not to challenge the decades in tech, but in this case, there are actually no files corresponding to the exact URL suffix (<whatever>.json). They are routes that are handled the following way:

1. Your webserver (Apache) gets the URL request for https://server/zm/api/host/getVersion.json
2. Apache looks to its site config to see how to handle this. In my case, I have this portion in:

/etc/apache2/sites-enabled/zoneminder-le-ssl.conf (You may just have zoneminder.conf)

Code: Select all

 # For better visibility, the following directives have been migrated from the
    # default .htaccess files included with the CakePHP project.
    # Parameters not set here are inherited from the parent directive above.
    <Directory "/usr/share/zoneminder/www/api">
       RewriteEngine on
       RewriteRule ^$ app/webroot/ [L]
       RewriteRule (.*) app/webroot/$1 [L]
       RewriteBase /zm/api
    </Directory>

    <Directory "/usr/share/zoneminder/www/api/app">
       RewriteEngine on
       RewriteRule ^$ webroot/ [L]
       RewriteRule (.*) webroot/$1 [L]
       RewriteBase /zm/api
    </Directory>

    <Directory "/usr/share/zoneminder/www/api/app/webroot">
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
        RewriteBase /zm/api
    </Directory>
Without getting into all details, what it tells apache is 'Hey if you get anything in the form of /zm/api/whatever please invoke "/usr/share/zoneminder/www/api/app/webroot/index.php" with that detail

If you look at index.php, that's where the magic happens, it bootstraps required components, and loads routes. The routes are where the actual mappings happen. Take a look at /usr/share/zoneminder/www/api/app/Config/routes.php

That basically connects your URL /host/getVersion.json to HostController.php which lies in your /usr/share/zoneminder/www/api/app/Controller directory.

I am explaining all of this because if its not working, your apache config should be the first place to check

Re: v1.37.1 API - enabling issue (zmninja app on iPhone)

Posted: Sun Oct 31, 2021 12:15 am
by lyallp
Awesome, what I was looking for.
As stated in my previous post, I found absolutely no url rewrites in my apache configurfation.
This explains why I could not find anything.
I will give it a what, googling, I am not the only one that has had issues with the API.
Thankyou.

EDIT: placing the rewrites in apache configuration for zoneminder worked! I searched my entire zoneminder installation for 'RewriteBase' and none where to be found, anywhere. So, my ebuild (Gentoo) needs examining.

EDIT: hangs head in embarrassment, apologises to all, after examining the ebuild, I found the RewriteBase config file in the documentation directory, along with the files that nobody reads. The only reason my install worked at all is I had previously installed it years ago, before the API was a thing. So I had all the appropriate zoneminder directory settings, minus the RewriteBase commands. There was no mention of this compressed readme file on installation. Once again, sorry all. :(

Re: [Solved] v1.37.1 API - enabling issue (zmninja app on iPhone)

Posted: Sun Oct 31, 2021 12:03 pm
by asker
Glad you got this sorted out!