API not working?

Discussions related to the 1.36.x series of ZoneMinder
Post Reply
RonRN18
Posts: 58
Joined: Tue Aug 13, 2019 1:00 am

API not working?

Post by RonRN18 »

I have a problem I can't seem to figure out. I don't believe the API portion is working, despite the fact I thought I had everything setup for it. On my Options -> System page, I have set OPT_USE_AUTH to enabled, AUTH_TYPE to builtin, AUTH_RELAY is hashed, AUTH_HASH_SECRET has a secret phrase created, AUTH_HASH_IPS is NOT enabled, AUTH_HASH_TTL is set to 2 hours, AUTH_HASH_LOGINS is enabled, ENABLE_CSRF_MAGIC is enabled (although I'm not quite sure what it does), OPT_USE_API is enabled, and OPT_USE_LEGACY_API_AUTH is enabled.

Under Options -> API, I have two different user accounts that have the API enabled.

I then followed the instructions on https://wiki.zoneminder.com/API about typing in "curl -X POST -d "user=somename&pass=somepass" http://serverip/zm/api/host/getVersion.json"... obviously changing the variables, such as my user and password and the server IP. When I submit the curl statement, absolutely nothing happens. I just get the prompt back immediately with nothing displayed. I would think that something ought to display to ensure it exits.

My reason for wanting this to work properly is primarily so that I can use a mobile app from my phone. I have both zmNinja and "Surveillance Pro" installed on my phone and they used to work before I gutted everything and started over from scratch.
RonRN18
Posts: 58
Joined: Tue Aug 13, 2019 1:00 am

Re: API not working?

Post by RonRN18 »

Apparently, I really FUBAR'd my setup. I uninstalled EVERYTHING again and started again from scratch. In the process, I changed from MariaDB to the official MySQL. I'm sure that had nothing to do with it. I believe my issue was that I was using PHP-FPM which I think screwed up the CGI aspect. Anyway, now that I've re-installed everything, all is working appropriately.
RonRN18
Posts: 58
Joined: Tue Aug 13, 2019 1:00 am

Re: API not working?

Post by RonRN18 »

OK... maybe I spoke too soon on the API portion working properly. When I run the "curl -X POST -d "user=somename&pass=somepass" http://serverip/zm/api/host/getVersion.json" statement with OPT_USE_LEGACY_API_AUTH enabled, I get:

Code: Select all

{"version":"1.36.18","apiversion":"2.0"}
If I disable OPT_USE_LEGACY_API_AUTH, I get:

Code: Select all

{"success":false,"data":{"name":"Not Authenticated","message":"Not Authenticated","url":"\/zm\/api\/host\/getVersion.json","exception":{"class":"UnauthorizedException","code":401,"message":"Not Authenticated"}}}
I am still unable to get mobile apps to connect. There is improvement though on "Surveillance Pro" from before re-installing everything. Before, when attempting to connect with "Surveillance Pro", when I entered the URL of my Zoneminder, it didn't know what type of system it was, as it works with many different systems. This time, it immediately recognized it as Zoneminder, it just would not authenticate.
User avatar
iconnor
Posts: 3197
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: API not working?

Post by iconnor »

So... don't disable legacy authentication. Legacy is the user=&pass= stuff.
Rashid Zuev
Posts: 2
Joined: Tue Jan 17, 2023 2:09 pm

Re: API not working?

Post by Rashid Zuev »

First, check the ZoneMinder logs for any errors or issues related to company info API requests. These logs can usually be found in the /var/log/zm/ directory on your server. Look for any error messages related to the API requests.

When you run the curl command for the company info API, it should provide some output. If you're not getting any response at all, it's possible that there's an issue with the command or the server configuration. Double-check the following:

1. Ensure that the ZoneMinder server is running and accessible from the machine where you are running the curl command. You should be able to access the ZoneMinder web interface without any issues.

2. Double-check the curl command and ensure that you have replaced user and pass with your actual credentials.

3. Verify that the server IP is correct, and there are no typos or network issues preventing the curl command from reaching the server.

You mentioned that you have two different user accounts with the API enabled. Ensure that these user accounts have the necessary permissions to access the API and perform the desired actions. Check the user settings in the ZoneMinder web interface and make sure they are properly configured.
Post Reply