Staff API PHP example

Discussion in 'Developing, APIs and extending' started by Bryan Gintz, Mar 15, 2012.

  1. Bryan Gintz

    Bryan Gintz New Member

    I am having some problems forming the CURL POST to do login authentication against my helpdesk. Does anyone have example code they could post?
     
  2. Ritu

    Ritu New Member

    $data = array('username' => $_POST['username'], 'password' => $_POST['password']);
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, 'http://youracccount.kayako.com/staffapi/index.php?/Core/Default/Login');
    curl_setopt ($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=".$_POST[username]."&password=".$_POST[password]);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
     
  3. Gurpreet Singh

    Gurpreet Singh Staff Member

    You can check this as well :

    $datatolog["username"] = utf8_encode("username");
    $datatolog["password"] = utf8_encode("password");
    $url = "http://helpdesk.com/staffapi/index.php?/staffapi/index.php?/Core/Default/Login ";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($datatolog,'','&'));
    curl_setopt($ch,CURLOPT_ENCODING , "gzip");
    $solution = curl_exec($ch);
    curl_close($ch);
    highlight_string($solution);
     

Share This Page