PHP cURL pull data from GenieACS

Dan Morphis dan at milkcarton.com
Wed May 20 16:48:11 EDT 2015


Are you querying the GUI or the NBI? I've never had to use auth on the NBI (port 7557). Only the GUI. 

-dan

> On May 20, 2015, at 9:53 AM, Richard Verbrugge <richard.verbrugge at myhighspeed.ca> wrote:
> 
> Hi folks,
>  
> I’m trying to use cURL to pull info from GenieACS using the API
> So, first I would login:
> $postdata = $url."?utf8=".$utf8."&authenticity_token=".$authenticity_token."&username=".$username."&password=".$password."&commit=".$commit;
>  
> This will probably fail due to the authenticity_token, I am not sure how to obtain this.
> Next I would run the query to obtain the ID of a device:
> $postquery = 'http://genieacsserver/devices/?query=%7B%22summary.pppoeusername%22%3A%22'.$pppoeusername;
>  
> Now cURL runs:
> $ch2 = curl_init();
> $agent = $_SERVER["HTTP_USER_AGENT"];
> curl_setopt($ch2, CURLOPT_USERAGENT, $agent);
> curl_setopt($ch2, CURLOPT_URL, $loginUrl );
> curl_setopt($ch2, CURLOPT_POST, 1 );
> curl_setopt($ch2, CURLOPT_POSTFIELDS, $postdata);
> curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);
> curl_setopt($ch2, CURLOPT_COOKIEJAR, 'cookie.txt');
> curl_setopt($ch2, CURLOPT_COOKIEFILE, 'cookie.txt');
> curl_setopt($ch2, CURLOPT_VERBOSE, 1);
> curl_setopt($ch2, CURLOPT_STDERR, $fp);
>   
> $postResult = curl_exec($ch2); //login
> curl_setopt($ch2, CURLOPT_URL, $postquery);
>  
> $exec = curl_exec($ch2); //get device ID
> $info = curl_getinfo($ch2);
> curl_exec($ch2);
>  
>  
> curl_close($ch2);
>  
> echo $exec; //return the device ID to  obtain other data with
>  
> How can you obtain the authenticity_token via cURL ? Any input on this cude is welcome!
>  
> Thanks,
> /RV
> _______________________________________________
> Users mailing list
> Users at lists.genieacs.com
> http://lists.genieacs.com/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.genieacs.com/pipermail/users/attachments/20150520/844f638a/attachment.html>


More information about the Users mailing list