API Error (zm 1.33.6)

Forum for questions and support relating to 1.33.x development only.
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

API Error (zm 1.33.6)

Post by Cramac1 »

login API

Code: Select all

	            $ch =  curl_init();
            curl_setopt( $ch, CURLOPT_URL, "http://site.ru/zm/api/host/login.json" );
			curl_setopt( $ch, CURLOPT_POST, 1);                //0 for a get request
            curl_setopt( $ch, CURLOPT_POSTFIELDS, "user=admin&pass=xxx" );
            curl_setopt( $ch, CURLOPT_COOKIEJAR,  dirname(__FILE__).'/cookie.txt' );
            $result = curl_exec( $ch );
            curl_close( $ch );
return:

Code: Select all

Fatal error: Cannot use 'object' as class name as it is reserved in /usr/share/zoneminder/www/api/lib/Cake/Core/Object.php on line 18
Call Stack
#	Time	Memory	Function	Location
1	0.0002	394928	{main}( )	.../index.php:0
2	0.3336	890672	Dispatcher->dispatch( )	.../index.php:107
3	0.4613	1059992	Dispatcher->_invoke( )	.../Dispatcher.php:167
4	0.4717	1145456	HostController->startupProcess( )	.../Dispatcher.php:189
5	0.4718	1156600	CakeEventManager->dispatch( )	.../Controller.php:677
6	0.4718	1156976	ComponentCollection->trigger( )	.../CakeEventManager.php:243
7	0.4718	1158208	CrudComponent->initialize( )	.../ObjectCollection.php:128
8	0.4719	1160456	CrudComponent->_loadListeners( )	.../CrudComponent.php:169
9	0.4719	1160832	CrudComponent->_loadListener( )	.../CrudComponent.php:728
10	0.4739	1215232	spl_autoload_call ( )	.../CrudComponent.php:752
11	0.4739	1215280	App::load( )	.../CrudComponent.php:752
12	0.4740	1217400	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/Listener/RelatedModelsListener.php' )	.../App.php:567
13	0.4740	1217400	spl_autoload_call ( )	.../RelatedModelsListener.php:13
14	0.4740	1217440	App::load( )	.../RelatedModelsListener.php:13
15	0.4741	1219184	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/CrudListener.php' )	.../App.php:567
16	0.4741	1219184	spl_autoload_call ( )	.../CrudListener.php:13
17	0.4741	1219224	App::load( )	.../CrudListener.php:13
18	0.4741	1221648	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/CrudBaseObject.php' )	.../App.php:567
19	0.4742	1221648	spl_autoload_call ( )	.../CrudBaseObject.php:14
20	0.4742	1221680	App::load( )	.../CrudBaseObject.php:14
21	0.4742	1223680	include( '/usr/share/zoneminder/www/api/lib/Cake/Core/Object.php' )	.../App.php:567
22	0.4742	1223680	class_alias ( )	.../Object.php:18

( ! ) Fatal error: Uncaught Error: Class 'RelatedModelsListener' not found in /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php on line 752
Call Stack
#	Time	Memory	Function	Location
1	0.0002	394928	{main}( )	.../index.php:0
2	0.3336	890672	Dispatcher->dispatch( )	.../index.php:107
3	0.4613	1059992	Dispatcher->_invoke( )	.../Dispatcher.php:167
4	0.4717	1145456	HostController->startupProcess( )	.../Dispatcher.php:189
5	0.4718	1156600	CakeEventManager->dispatch( )	.../Controller.php:677
6	0.4718	1156976	ComponentCollection->trigger( )	.../CakeEventManager.php:243
7	0.4718	1158208	CrudComponent->initialize( )	.../ObjectCollection.php:128
8	0.4719	1160456	CrudComponent->_loadListeners( )	.../CrudComponent.php:169
9	0.4719	1160832	CrudComponent->_loadListener( )	.../CrudComponent.php:728
10	0.4739	1215232	spl_autoload_call ( )	.../CrudComponent.php:752
11	0.4739	1215280	App::load( )	.../CrudComponent.php:752
12	0.4740	1217400	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/Listener/RelatedModelsListener.php' )	.../App.php:567
13	0.4740	1217400	spl_autoload_call ( )	.../RelatedModelsListener.php:13
14	0.4740	1217440	App::load( )	.../RelatedModelsListener.php:13
15	0.4741	1219184	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/CrudListener.php' )	.../App.php:567
16	0.4741	1219184	spl_autoload_call ( )	.../CrudListener.php:13
17	0.4741	1219224	App::load( )	.../CrudListener.php:13
18	0.4741	1221648	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/CrudBaseObject.php' )	.../App.php:567
19	0.4742	1221648	spl_autoload_call ( )	.../CrudBaseObject.php:14
20	0.4742	1221680	App::load( )	.../CrudBaseObject.php:14
21	0.4742	1223680	include( '/usr/share/zoneminder/www/api/lib/Cake/Core/Object.php' )	.../App.php:567
22	0.4742	1223680	class_alias ( )	.../Object.php:18
( ! ) Error: Class 'RelatedModelsListener' not found in /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php on line 752
Call Stack
#	Time	Memory	Function	Location
1	0.0002	394928	{main}( )	.../index.php:0
2	0.3336	890672	Dispatcher->dispatch( )	.../index.php:107
3	0.4613	1059992	Dispatcher->_invoke( )	.../Dispatcher.php:167
4	0.4717	1145456	HostController->startupProcess( )	.../Dispatcher.php:189
5	0.4718	1156600	CakeEventManager->dispatch( )	.../Controller.php:677
6	0.4718	1156976	ComponentCollection->trigger( )	.../CakeEventManager.php:243
7	0.4718	1158208	CrudComponent->initialize( )	.../ObjectCollection.php:128
8	0.4719	1160456	CrudComponent->_loadListeners( )	.../CrudComponent.php:169
9	0.4719	1160832	CrudComponent->_loadListener( )	.../CrudComponent.php:728
10	0.4739	1215232	spl_autoload_call ( )	.../CrudComponent.php:752
11	0.4739	1215280	App::load( )	.../CrudComponent.php:752
12	0.4740	1217400	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/Listener/RelatedModelsListener.php' )	.../App.php:567
13	0.4740	1217400	spl_autoload_call ( )	.../RelatedModelsListener.php:13
14	0.4740	1217440	App::load( )	.../RelatedModelsListener.php:13
15	0.4741	1219184	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/CrudListener.php' )	.../App.php:567
16	0.4741	1219184	spl_autoload_call ( )	.../CrudListener.php:13
17	0.4741	1219224	App::load( )	.../CrudListener.php:13
18	0.4741	1221648	include( '/usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Crud/CrudBaseObject.php' )	.../App.php:567
19	0.4742	1221648	spl_autoload_call ( )	.../CrudBaseObject.php:14
20	0.4742	1221680	App::load( )	.../CrudBaseObject.php:14
21	0.4742	1223680	include( '/usr/share/zoneminder/www/api/lib/Cake/Core/Object.php' )	.../App.php:567
22	0.4742	1223680	class_alias ( )	.../Object.php:18
23	0.4751	1232096	App::shutdown( )	.../App.php:0
24	0.4754	1232128	App::_checkFatalError( )	.../App.php:943
25	0.4754	1232792	ErrorHandler::handleError( )	.../App.php:970
26	0.4754	1232792	ErrorHandler::handleFatalError( )	.../ErrorHandler.php:212
27	0.5057	1219448	ErrorHandler::handleException( )	.../ErrorHandler.php:269
28	0.5062	1221376	ExceptionRenderer->__construct( )	.../ErrorHandler.php:126
29	0.5062	1221376	ExceptionRenderer->_getController( )	.../ExceptionRenderer.php:95
30	0.5069	1301400	CakeErrorController->startupProcess( )	.../ExceptionRenderer.php:158
31	0.5070	1312544	CakeEventManager->dispatch( )	.../Controller.php:677
32	0.5070	1312920	ComponentCollection->trigger( )	.../CakeEventManager.php:243
33	0.5071	1314152	CrudComponent->initialize( )	.../ObjectCollection.php:128
34	0.5072	1318640	CrudComponent->_loadListeners( )	.../CrudComponent.php:169
35	0.5072	1319016	CrudComponent->_loadListener( )	.../CrudComponent.php:728
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: API Error (zm 1.33.6)

Post by rockedge »

that is odd! This error was fixed some time ago with version 1.31+. It is because of changes in CRUD to deal with PHP 7.2+ and a change causes the problem. look this over and see if this is what your problem is viewtopic.php?p=105092#p105092
SpikeyGG
Posts: 60
Joined: Mon Oct 15, 2012 12:02 am

Re: API Error (zm 1.33.6)

Post by SpikeyGG »

When I try to navigate to the url: http://myhost/zm/api/host/getVersion.json to test the API, the I see this error message:

Code: Select all

<br />
<b>Fatal error</b>:  Uncaught Error: Call to undefined function apc_fetch() in /usr/share/zoneminder/www/api/lib/Cake/Cache/Engine/ApcEngine.php:91
Stack trace:
#0 /usr/share/zoneminder/www/api/lib/Cake/Cache/Cache.php(363): ApcEngine-&gt;read('myapp_cake_core...')
#1 /usr/share/zoneminder/www/api/lib/Cake/I18n/I18n.php(235): Cache::read('cake_dev_en-us', '_cake_core_')
#2 /usr/share/zoneminder/www/api/lib/Cake/basics.php(636): I18n::translate('Cache engine &quot;%...', NULL, 'cake_dev')
#3 /usr/share/zoneminder/www/api/lib/Cake/Cache/Cache.php(184): __d('cake_dev', 'Cache engine &quot;%...', '_cake_core_')
#4 /usr/share/zoneminder/www/api/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_')
#5 /usr/share/zoneminder/www/api/app/Config/core.php(375): Cache::config('_cake_core_', Array)
#6 /usr/share/zoneminder/www/api/lib/Cake/Core/Configure.php(72): include('/usr/share/zone...')
#7 /usr/share/zoneminder/www/api/lib/Cake/bootstrap.php(442): Configure::bootstrap(true)
#8 /usr/share/zoneminder/www/api/app/webroot/index.php(90): incl in <b>/usr/share/zoneminder/www/api/lib/Cake/Cache/Engine/ApcEngine.php</b> on line <b>91</b><br />
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

Re: API Error (zm 1.33.6)

Post by Cramac1 »

updated to zoneminder (1.33.6~20190428120633-bionic)
here all the rules
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

Re: API Error (zm 1.33.6)

Post by Cramac1 »

Only viewing online pictures does not work.
Error:
zms_m2 Dav 9241 ERR Unable to authenticate user

I pass authorization,
I see a list of monitors,
I want to see a picture, but he does not give:

Code: Select all

	<img src="http://video.site.ru/zm/cgi-bin/nph-zms?scale=auto&width=1920px&height=1080px&mode=jpeg&maxfps=30&monitor='.$monitid.'&auth='.$authkey.'&connkey=365675&rand=1555067025" />
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: API Error (zm 1.33.6)

Post by rockedge »

do you have Options->Systems->AUTH_HASH_LOGINS enabled?
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

Re: API Error (zm 1.33.6)

Post by Cramac1 »

rockedge wrote: Tue Apr 30, 2019 7:46 pm do you have Options->Systems->AUTH_HASH_LOGINS enabled?
yes
Безымянный.gif
Безымянный.gif (116.93 KiB) Viewed 15466 times
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

Re: API Error (zm 1.33.6)

Post by Cramac1 »

auth return:

Code: Select all

Array ( [access_token] => eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJab25lTWluZGVyIiwiaWF0IjoxNTYwNTkxMDU4LCJleHAiOjE1NjA1OTQ2NTgsInVzZXIiOiJhZG1pbiIsInR5cGUiOiJhY2Nlc3MifQ.TSVWYhUl_kN3NUZvNP6cRAg0N_mUqDImi_vUNJPtIuY [access_token_expires] => 3600 [refresh_token] => eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJab25lTWluZGVyIiwiaWF0IjoxNTYwNTkxMDU4LCJleHAiOjE1NjA2Nzc0NTgsInVzZXIiOiJhZG1pbiIsInR5cGUiOiJyZWZyZXNoIn0.m3XbmgqBoqu-ACTr4I_Wns_5kV6tZG6MnxHqDNwO1F0 [refresh_token_expires] => 86400 [credentials] => auth=997617e10b0716c850be6c54b3769077 [append_password] => 0 [version] => 1.33.9 [apiversion] => 2.0 ) )
img get:

Code: Select all

https://video.site.ru/zm/cgi-bin/nph-zms?scale=auto&width=1920px&height=1080px&mode=jpeg&maxfps=30&monitor=2&auth=997617e10b0716c850be6c54b3769077&connkey=365675&rand=1555067025
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: API Error (zm 1.33.6)

Post by asker »

That looks correct. Are you facing a problem?
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
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

Re: API Error (zm 1.33.6)

Post by Cramac1 »

Yes, there is a problem, the video does not go, in the log: ERR Unable to authenticate user
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: API Error (zm 1.33.6)

Post by asker »

When did you last update ZM? Some auth stuff was fixed recently
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
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

Re: API Error (zm 1.33.6)

Post by Cramac1 »

yesterday just updated

[version] => 1.33.9
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: API Error (zm 1.33.6)

Post by asker »

1. Create a AUTH_HASH_SECRET
2. Make sure you restart ZM
4. Look at your Users table in your DB - do all the passwords start with "$2" something? If not, you have a problem. Run "sudo zmupdate.pl -f" and make sure all passwords start with "$2". Then, log into each user you need to use using ZM console and then try your code.

-- other option ---
1. What happens if you change your code to use the new token system? That is, replace "&auth=" with "&token=" and use "access_token" key (new API docs here)
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
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

Re: API Error (zm 1.33.6)

Post by Cramac1 »

asker wrote: Sun Jun 16, 2019 1:02 pm 1. Create a AUTH_HASH_SECRET

-- other option ---
1. What happens if you change your code to use the new token system? That is, replace "&auth=" with "&token=" and use "access_token" key (new API docs here)
made a new AUTH_HASH_SECRET and replaced auth with a token
and now it works

thx
Cramac1
Posts: 111
Joined: Wed Aug 29, 2018 11:29 am

Re: API Error (zm 1.33.6)

Post by Cramac1 »

The new question is, in what encoding does the API return the name? in zm web:
Запись- 53703

in api:
[Name] => Запись- 50857

Russian text
Locked