Login and Session Share API
This API enables you to authenticate an e-mail address and password against the SPBAS database. Successful authentication returns the user information along with the SPBAS session ID for the user.
We also provide additional functionality that enables you to pass in extra data to automatically create the user and/or customer account if they do not already exist.
The API accepts the following parameters:
| Parameter | Required | Datatype | Description |
| Yes | String | E-mail address to authenicate | |
| password | Yes | String | Password to authenicate |
| create_user | No | Boolean | true for yes; false for no |
| first_name | No | String | Requires create_user set to true |
| last_name | No | String | Requires create_user set to true |
| username | No | String | Requires create_user set to true |
| create_customer | No | Boolean | true for yes; false for no |
| company_name | No | String | Requires create_customer and create_user set to true |
| include_address | No | Boolean | true for yes; false for no |
If you set create_user to true then first_name, last_name and username are required.
If you set create_customer to true then company_name is required and you must set create_user to true.
Accessing the API
The API is based on our REST API and can be accessed via a raw form post or by using our standard libraries which are distributed with every copy of SPBAS. We recommend that you use our standard libraries for PHP integrations.
Our standard libraries are located in the following directories of each storefront. The storefront is made up of the order/, customers/, kb/ and cms/ directories.
*storefront*/includes/functions.php
*storefront*/includes/classes/api.php
*storefront*/includes/classes/api_wrappers.php
*storefront*/includes/functions.php
*storefront*/includes/classes/api.php
*storefront*/includes/classes/api_wrappers.php
Here's how you connect to the API using our standard libraries:
include_once 'api.php';
include_once 'functions.php';
// from m3_configuration.php
// ---------------------------------------------------------------------------------
$api_home='http://your-domain.com/spbas/api/index.php';
$api_key='abc123'; // SPBAS Admin -> Settings -> Advanced
// the API call
// ---------------------------------------------------------------------------------
$module='customer_areas';
$task='loginshare';
// Required Data
// ---------------------------------------------------------------------------------
$data=array();
$data['email']='user@email.com';
$data['password']='test';
// Optionial Data
// ---------------------------------------------------------------------------------
$data['create_user']=true; // true/false - true creates the user if not exists
$data['first_name']='Albert';
$data['last_name']='Wesker';
$data['username']='wesker';
$data['create_customer']=true; // true/false - true creates the customer record too
$data['company_name']='Umbrella Corporation';
$data['include_address']=true; // true/false - true returns the primary customer address
$result=api::query($api_home, $api_key, $module, $task, $data, false);
// Something didn't go right! Die here and print the errors.
if (!$result['session_id']) { pr($result['errors']); }
// Start the session! SPBAS must be on the same server for this to work.
set_cookie('customer_session', $result['session_id'], time()+2538000);
// The full response. Note that the password is simply md5('plain text password').
pr($result);



