Hi,
I will like some help to ensure how to get access to API by using PHP curl.
Issue is when auth is activated. So to map with this command : curl -d "username=XXXX&password=YYYY&action=login&view=console" -c cookies.txt http://yourzmip/zm/index.php
Actually I try :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $addr . '/api/index.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/zmcookies.txt');
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS
$json_string = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
But I get insulted by cakePHP :
CakePHP: the rapid development php framework: Errors CakePHP: the rapid development php framework Not Authenticated Error: The requested address '/zm/api/' was not found on this server. Stack Trace [internal function] → AppController->beforeFilter(CakeEvent) object(CakeEvent) { data => null result => null [protected] _name => 'Controller.initialize' [protected] _subject => object(PagesController) {} [protected] _stopped => false } CORE/Cake/Event/CakeEventManager.php line 244 → call_user_func(array, CakeEvent) if ($listener['passParams'] === true) { $result = call_user_func_array($listener['callable'], $event->data); } else { $result = call_user_func($listener['callable'], $event); } array( (int) 0 => object(PagesController) {}, (int) 1 => 'beforeFilter' ) object(CakeEvent) { data => null result => null [protected] _name => 'Controller.initialize' [protected] _subject => object(PagesController) {} [protected] _stopped => false } CORE/Cake/Controller/Controller.php line 674 → CakeEventManager->dispatch(CakeEvent) * @return void */ public function startupProcess() { $this->getEventManager()->dispatch(new CakeEvent('Controller.initialize', $this)); $this->getEventM
And it continues (by the way, I don't know if it's normal to have the API answer with so much details and informations)
I will try by curl in bash tonight, but that's weird the answer cannot find /zm/api as whatever cakePHP answer ...
API and PHP calls with curl
Re: API and PHP calls with curl
Code: Select all
<?php
$username = 'xxxx';
$password = 'yyyy';
$loginUrl = 'http://mysite/zm/index.php';
$apiUrl = 'http://mysite/zm/api';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$username.'&password='.$password.'&action=login&view=console');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec($ch);
#turn off POST after login - important
curl_setopt($ch, CURLOPT_POST, 0);
print "---------- Version API -----------------";
curl_setopt($ch, CURLOPT_URL, $apiUrl."/host/getVersion.json");
$content = curl_exec($ch);
print $content;
print "---------- Your Monitors -----------------";
curl_setopt($ch, CURLOPT_URL, $apiUrl."/monitors.json");
$content = curl_exec($ch);
print $content;
curl_close($ch);
?>
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
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
Re: API and PHP calls with curl
Thanks, perfect
Re: API and PHP calls with curl
Another question, related to the controls through the API.
So, I read the documentation and understand that on monitors you have only if it's controllable, the controlable ID.
Ok, get this. Get also the details of the controls by calling controls/XX.json
But how to call Zoneminder to request a movable avalaible ? as one side you have the monitors and the others the controls but no matchs.
I take a look on web interface, it's sending some paramaters like request controls and the type of control like MoveUpRight
Once we know what control is avalaible for a monitor. Do we need to call the "index.php" URL to move the camera ?
So, I read the documentation and understand that on monitors you have only if it's controllable, the controlable ID.
Ok, get this. Get also the details of the controls by calling controls/XX.json
But how to call Zoneminder to request a movable avalaible ? as one side you have the monitors and the others the controls but no matchs.
I take a look on web interface, it's sending some paramaters like request controls and the type of control like MoveUpRight
Once we know what control is avalaible for a monitor. Do we need to call the "index.php" URL to move the camera ?
Re: API and PHP calls with curl
You need to send POST commands to zms. Open up ZM console, go to Ptz commands and right click - inspect source. That will give you a function name. Search for it in the zoneminder code and you will see how ZM does it. Replicate that in your code.
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
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