mikebloom Posted July 15, 2014 Report Posted July 15, 2014 Hi, I'm trying to use the blesta api to login clients but I can't get it to work. Other API calls is working e.g. users get. Could somebody maybe explain to me how the API works and help me out with my script, I'm guessing it has something to do with sessions. I'm getting a blank page with the following code: <?php require_once "blesta_api.php"; $user = "api"; $key = "70db2394eb4aa4575fcd1899ee1ed951"; $url = "http://192.168.1.1/index.php/api/"; $api = new BlestaApi($url, $user, $key); $data = array( 'vars' => array( 'username' => "test", 'password' => "password", 'remember_me' => "false", 'ip_address' => "192.168.0.1" ) ); $response = $api->get("users", "login", $data); print_r($response->response()); print_r($response->errors()); ?> Regards, Mike Quote
Tyson Posted July 15, 2014 Report Posted July 15, 2014 Yes, it doesn't look like you're passing in a reference to the session. Users::login() requires the first parameter to be the session, followed by the vars, but you have vars as the first paramater. You should also perform a post request, rather than get for that action. If you're attempting to setup a shared login with another system, you may want to use the Shared Login plugin instead. Quote
lawrence-ytz Posted December 1, 2014 Report Posted December 1, 2014 I'm having the similar issue, what type of data needs to be passed in the Session parameter? The error I'm recieving is: object(stdClass)#4 (1) { ["error"]=> object(stdClass)#3 (2) { ["message"]=> string(28) "An unexpected error occured." ["response"]=> string(25) "Parameter is not optional" } } Parameter is not optional My code is as below: $data = array( 'Session' => 123456, 'vars' => array( 'username' => $email, 'password' => $password, 'remember_me' => false, 'ip_address' => '1.1.1.1' ) ); $response = $api->post("users", "login", $data); Quote
Tyson Posted December 1, 2014 Report Posted December 1, 2014 As shown in the docs, the first parameter must be an object of type Session, which represents the user's session. The Session is a component included with Blesta. Quote
lawrence-ytz Posted December 1, 2014 Report Posted December 1, 2014 So how can the Session Cookie be set if the api only supports calling Model methods, and setSessionCookie is a component? Quote
Tyson Posted December 1, 2014 Report Posted December 1, 2014 Users::login attempts to set a session cookie if you set $vars['remember_me'] to true, if the Session already contains an entry for "blesta_session_cookie" which is set to true, and the user does not require two factor authentication. Since you pass in the Session to that method, you can set your own cookie instead by calling it directly. Quote
lawrence-ytz Posted December 1, 2014 Report Posted December 1, 2014 Well I wouldn't want to set remember_me to true to get around it. I've given up on users::login, and am now trying to use users::auth, but it keeps returning false, is the password parameter plane text or encrypted? Quote
Tyson Posted December 1, 2014 Report Posted December 1, 2014 Yes, the password is expected to be given in plain text. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.