Site Offline

This site has been deprecated and all functionality has been taken offline. What you're viewing now is a static HTML mirror preserved for posterity

The API endpoints are currently online, but will be removed from service later in 2017

What is the PHP API Client?

Our API is incredibly simple to use, but to make life even easier, our Basic, Full and Unlimited subscribers have access to a prebuilt integration library. 

This documentation details how to implement and use the library.

 

Adding the Client to your Project

Adding the client to your project is simply a case of downloading the client file, and unzipping the archive into the location you desire. For the sake of example, we'll assume you've extracted into a sub-directory called libraries.

 

Using the Client in your Project

The library contains a number of pre-configured requests, but also provides the ability to place custom requests. To begin with, we'll place a request to retrieve the Latest Results for all lotteries.

Pre-Configured Requests

 

// Include the Library file
require_once('libraries/LotteryResults.class.php');

// Set the API Credentials
$params->key = 'myAPIkey';
$params->sec = 'myAPISecret';

// Instantiate the object
$lottery = new LotteryResultsAPI($params);

// Place the request - We get an object back. If the request failed we get false
if(!$results = $lottery->getLatestResults()){
echo "Error";
die;
}

// We can now check the API Response status
if ($results->status != "ok"){
echo "API Reports an error";
die;
}

// Otherwise we can use the data in $results->response
foreach ($results->response as $lottery=>$data){
echo "Raw results for $lottery are {$data->resultsraw}";
}

 

 

Custom Requests

There may be occasions when you want to send a customised request to the API - especially if you're an Unlimited subscriber making use of experimental features. To do so, we simply use the setAction and addRequestBody methods. In the example below, we'll make a call to UserCheck.

// Include the Library file
require_once('libraries/LotteryResults.class.php');

// Set the API Credentials
$params->key = 'myAPIkey';
$params->sec = 'myAPISecret';

// Instantiate the object
$lottery = new LotteryResultsAPI($params);

// This time, we want to set the action manually
$lottery->setAction('UserCheck');

// Set the game ID
$lottery->setGame(1);

// We can also pass in an object
$balls = new stdClass();
$balls->ball1 = 1;
$balls->ball2 = 10;
$balls->ball3 = 18;
$balls->ball4 = 22;
$balls->ball5 = 5;
$balls->ball6 = 27;
$balls->ball7 = 4;
$lottery->addRequestBody('balls',$balls);

// Finally, let's send the request
list($status,$response) = $lottery->placeRequest()
if ($status != "ok"){
echo "API Reports an error";
die;
}

// data is in $response->response as before

Data format

All data returned from the API is converted from JSON to an Object. Response data is always under response, whilst the API status is under status;

$data->status // Will be okor Error
$data->error  // Empty if no error, error specific information otherwise.
$data->response // Object containing the data returned.

Pre-Configured Requests

The client has the following preconfigured request methods

RequestArgumentsRetrieves
getLatestResults   Latest results from all supported lotteries
getAllGames   Retrieve a list of all supported lotteries
getGames   Get all lotteries to which your API Key has access
keyCheck   Check that the configured API Key is enabled
getDrawResult $game - INT - Lottery ID
$draws (optional) - Draw day (e.g. Wed)
Get the latest draw result for the given draw day. If a day is not specified the results will be for the most recent draw