This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Adrien - ACTE Solutions
Adrien - ACTE Solutions

Hi all, this is my first post on this forum :-) I am trying to connect on an external API. My script is a simple curl post and is working fine when running in php, however, I can't make it work in a controller, I can't see any errors (I am in debug mode)

Any idea?

Thanks.

function oc_login()
{
    $username=Settings::get('username');
    $key=Settings::get('api_key');
    $url = "https://api.example.com/index.php?route=api/login";

  $params = array(
      "key=$key",
  "username=$username"
      );

  $parameters = implode('&', $params);
  $ch = curl_init();
  curl_setopt($ch,CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch,CURLOPT_POSTFIELDS, $parameters);

  //execute post
  $result = curl_exec($ch);

  //close connection
  curl_close($ch);

  dd($parameters, $result);
  // key and username on $parameter OK
  // $result is supposed to be a JSON but is empty: []
  // $result when running in php look like this: {"success":"Success: API session successfully started!","api_token":"xxxxxxxxxxxxxxxx"}

  //var_dump($result);
  return $result;

}

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.