<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Are you querying the GUI or the NBI? I've never had to use auth on the NBI (port 7557). Only the GUI. <br><br>-dan</div><div><br>On May 20, 2015, at 9:53 AM, Richard Verbrugge <<a href="mailto:richard.verbrugge@myhighspeed.ca">richard.verbrugge@myhighspeed.ca</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        mso-fareast-language:EN-US;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Segoe UI","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--><div class="WordSection1"><p class="MsoNormal">Hi folks,<o:p></o:p></p><p class="MsoNormal"><o:p> </o:p></p><p class="MsoNormal">I’m trying to use cURL to pull info from GenieACS using the API<o:p></o:p></p><p class="MsoNormal">So, first I would login:<o:p></o:p></p><p class="MsoNormal" style="text-indent:36.0pt"><span style="font-family:Consolas">$postdata = $url."?utf8=".$utf8."&authenticity_token=".$authenticity_token."&username=".$username."&password=".$password."&commit=".$commit;<o:p></o:p></span></p><p class="MsoNormal"><o:p> </o:p></p><p class="MsoNormal">This will probably fail due to the authenticity_token, I am not sure how to obtain this.<o:p></o:p></p><p class="MsoNormal">Next I would run the query to obtain the ID of a device:<o:p></o:p></p><p class="MsoNormal" style="text-indent:36.0pt"><span style="font-family:Consolas">$postquery = '<a href="http://genieacsserver/devices/?query=%7B%22summary.pppoeusername%22%3A%22'.$pppoeusername">http://genieacsserver/devices/?query=%7B%22summary.pppoeusername%22%3A%22'.$pppoeusername</a>;<o:p></o:p></span></p><p class="MsoNormal"><o:p> </o:p></p><p class="MsoNormal">Now cURL runs:<o:p></o:p></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">$ch2 = curl_init();<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">$agent = $_SERVER["HTTP_USER_AGENT"];<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_USERAGENT, $agent);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_URL, $loginUrl );<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_POST, 1 );<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_POSTFIELDS, $postdata);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_COOKIEJAR, 'cookie.txt');<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_COOKIEFILE, 'cookie.txt');<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_VERBOSE, 1);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_STDERR, $fp);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">   <o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">$postResult = curl_exec($ch2); //login<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_setopt($ch2, CURLOPT_URL, $postquery);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"><o:p> </o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">$exec = curl_exec($ch2); //get device ID<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">$info = curl_getinfo($ch2);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_exec($ch2);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"><o:p> </o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"><o:p> </o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">curl_close($ch2);<o:p></o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"><o:p> </o:p></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">echo $exec</span>; //return the device ID to  obtain other data with<o:p></o:p></p><p class="MsoNormal"><o:p> </o:p></p><p class="MsoNormal">How can you obtain the authenticity_token via cURL ? Any input on this cude is welcome!<o:p></o:p></p><p class="MsoNormal"><o:p> </o:p></p><p class="MsoNormal">Thanks,<o:p></o:p></p><p class="MsoNormal">/RV<o:p></o:p></p></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Users mailing list</span><br><span><a href="mailto:Users@lists.genieacs.com">Users@lists.genieacs.com</a></span><br><span><a href="http://lists.genieacs.com/mailman/listinfo/users">http://lists.genieacs.com/mailman/listinfo/users</a></span><br></div></blockquote></body></html>