Jump to content

Api Users Login


mikebloom

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 months later...

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);
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...