The WellnessLiving software development kit (SDK) can be installed like any other SDK. It has been tested with PHP 5.5 and above. If you’re experiencing any issues with a PHP version that should be compatible with our SDK, please reach out using the Contact us page..
When installing the SDK, it’s important not to alter the internal directory structure of the SDK.
Downloading the SDK
To download the SDK, visit WellnessLiving’s GitHub repository at github.com/wellnessliving/wl-sdk. You can download our SDK as a ZIP file.
Configuring the SDK
Once you’ve downloaded the SDK, we recommend storing it somewhere that’s easy for you to access frequently.
To get started, you’ll need the following pieces of information:
- Your authorization code and ID, which are set in example-config.php.
- Your username, password, and business ID (BID), which are set in example-sdk.php. The username and password are values used in the example call to the EnterModel endpoint, and the BID is used in the call to the DataModel endpoint.
The uid value isn’t used in this example, but it’s relevant for many other calls and should be noted for later.
To run the SDK test example call, ensure that you’ve edited example-config.php and example-sdk.php to include your credentials, as your username must be set in both files.
Testing the SDK example call
The SDK includes an example call that retrieves a copy of the All Sales Report for your Staging business. The example should run with no warnings or errors, outputting all information for the current month. Each report is structured like a spreadsheet, with every line item represented by a new row. If your business is new, the example call may return zero rows.
Sample invocation on the command line:
php example-sdk.php
Sample output (simulated data from a business):
1. 2022-12-08 45.45 Mike Roberts 1 Year Appointment Membership 2. 2022-12-15 20.20 Jose Sanchez 1 Month Appointment Membership 3. 2022-12-16 75.00 Jerome Cartier 5 Class Membership 4. 2022-12-16 10.00 Jerome Cartier Soap (Red) 5. 2022-12-16 20.20 Jerome Cartier Towel 6. 2022-12-18 75.00 Joe Johnson 5 Class Membership 7. 2022-12-20 75.00 Lily Lexington 5 Class Membership 8. 2022-12-20 50.00 Chuck Liddell 3 Month Appointment Membership 9. 2022-12-20 200.00 Chuck Liddell 20 Class Membership 10. 2022-12-21 75.00 Jerome Cartier 5 Class Membership 11. 2022-12-21 20.00 Jerome Cartier 10 Class Pass 12. 2022-12-21 20.20 Jerome Cartier Towel 13. 2022-12-24 75.00 Laura Ross 5 Class Membership 14. 2022-12-25 75.00 Laura Ross 5 Class Membership 15. 2022-12-29 50.00 Denise Williams 1 on 1 Personal Training 16. 2022-12-29 20.00 Anna Sanchez Kickboxing: Online 17. 2022-12-29 25.00 Anna Sanchez Crossfit Training 18. 2022-12-29 20.00 Anna Sanchez Ballet: Beginner 19. 2022-12-29 50.00 Denise Williams 1 on 1 Personal Training 20. 2022-12-29 15.15 Denise Williams Towel 21. 2022-12-29 20.00 Denise Williams Private Group Bhangra Dance
Understanding the SDK example call
The example-sdk.php file is used for this SDK example call.
There are three main parts of the example code:
- Signing in a user to the system
- Executing the request
- Using the result
In most cases, you’ll need to be signed in to use the SDK. Your SDK access relates to your user privileges. For instance, a user who’s an employee of one business can’t change classes for another business.
SDK calls can be made for clients and staff members. These two user groups can be used if you need to limit the data returned or options presented to specific users. Note that some endpoints don’t require access or authentication. In such cases, you won’t need to be signed in as a user to run those endpoints.
For the example code below, you’ll need access to the All Sales Report in WellnessLiving. You can use either the user credentials given with the SDK or the credentials of a staff member with access to reports.
The first step when signing in is to select the server region you want to use. For your Staging business, you’ll automatically use the North Virginia (United States) region. When signing in with your Production credentials for the first time, contact us to determine whether you should be using the North Virginia (United States) or New South Wales (Australia) region.
To sign in to the system, you must create a Notepad object to establish a session. You can then hit the EnterModel endpoint with your WellnessLiving username and encrypted password. This allows us to set and use a cookie to perform full authentication with the password.
$o_config=ExampleConfig::create(WlRegionSid::US_EAST_1); // Retrieve the notepad string (this is a separate step in the user sign-in process). $o_notepad=new NotepadModel($o_config); $o_notepad->get(); // Sign in the user. $o_enter=new EnterModel($o_config); $o_enter->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_enter->s_login='/** Put your login here */'; $o_enter->s_notepad=$o_notepad->s_notepad; $o_enter->s_password=$o_notepad->hash('/** Put your password here */'); $o_enter->post();
After you’ve signed in, you can begin creating the DataModel object necessary to retrieve the report data. You’ll need to set four values to specify the report you want, along with the day, week, or month for which you want it. Once all values are set, use the get method to call the object.
$o_report=new DataModel($o_config); $o_report->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_report->id_report_group=WlReportGroupSid::DAY; $o_report->id_report=WlReportSid::PURCHASE_ITEM_ACCRUAL_CASH; $o_report->k_business='2149'; // Put your business key here. $o_report->filterSet([ 'dt_date' => '2018-08-21' ]); $o_report->get();
The example writes all the report’s information to the screen. Different calls will return data in various formats, so it’s important to check the documentation for details and test thoroughly.
$i=0; foreach($o_report->a_data['a_row'] as $a_row) { $i++; echo $i.'. '.$a_row['dt_date'].' '.$a_row['f_total']['m_amount'].' '.$a_row['o_user']['text_name'].' '.$a_row['s_item']."\r\n"; }
The SDK uses exceptions to communicate when an error has occurred. In this example, exceptions are printed to the screen.
catch(WlAssertException $e) { echo $e; return; } catch(WlUserException $e) { echo $e->getMessage()."\n"; return; }
Using the SDK on different servers
WellnessLiving maintains two development servers and two production server clusters.
The two development servers are demo.wellnessliving.com, where our newest code is tested and staging.wellnessliving.com, which has a more stable set of changes.
Our two production server clusters are us.wellnessliving.com and au.wellnessliving.com. These server clusters are used for the United States cluster located in Virginia (United States) and the Asia Pacific cluster located in New South Wales (Australia), respectively.
We strive to make calls between the different servers as consistent as possible, but there are small differences regarding how calls to different servers are made. All our servers use HTTPS.
Keep in mind that when moving to a different server, identifiers, keys, and code will differ.
Setting Demo or Staging configurations
The default example-config.php contains the following lines:
use WellnessLiving\Config\WlConfigDeveloper; class ExampleConfig extends WlConfigDeveloper
This lets us know example-config.php is set up to use the Demo and Staging servers. If you want to make calls to one of the Production servers, use the following code:
use WellnessLiving\Config\WlConfigProduction; class ExampleConfig extends WlConfigProduction
Configuring API calls
To configure your API calls to work with a different server, you’ll need to update the URL and the names of the cookies used. WellnessLiving uses both a persistent and a transient cookie to maintain sessions. These cookies are typically abbreviated using the first letter of the server and the type of cookie. For example, on the demo server, the persistent cookie is named dp. On the Asia Pacific cluster, the transient cookie is named at.
For more information about cookies used by WellnessLiving, see Cookies.
Server Name | Server URL | Cookie Names |
Development, Demo | demo.wellnessliving.com | dp, dt |
Development, Staging | staging.wellnessliving.com | sp, st |
Production, North America | us.wellnessliving.com | p, t |
Production, Asia Pacific | au.wellnessliving.com | ap, at |