API and PHP calls with curl
Posted: Fri Feb 26, 2016 4:33 pm
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 ...
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 ...