SageOne Accounting API Wrapper (PHP)
This is a simple API wrapper library for SageOne Accounting platform., (*1)
Official API Documentation & API sign up can be found at: https://accounting.sageone.co.za/Marketing/DeveloperProgram.aspx, (*2)
Courtesy of the Tow.com.au team :) - https://www.tow.com.au, (*3)
With composer, add to your composer.json :, (*4)
{ "require": { "tow-com-au/sageone-php": "dev-master" } }
If you are new to composer, here is some simple steps to take., (*5)
php ./composer.phar install
The composer will create a directory named vendor and download all required libraries into it., (*6)
In the vendor directory, there's also a file named autoload.php. This is the PHP autoloader for the libraries inside. You might need to register it to you existing autoloader, or include it manually., (*7)
To login to the SageOne API you will need two things. First, an 'AuthCode', which can be generated from your login details in the format base64_encode('username:password'), and second, an API key as requested from SageOne., (*8)
// You will need to include this autoload script manually // if you don't have any autoloader setup. include "../path/to/vendor/autoload.php"; // Use your login to request an API key from: // https://accounting.sageone.co.za/Marketing/DeveloperProgram.aspx $apiKey = '{api key goes here}'; $authCode = base64_encode('username:password'); // SageOne will provide you with a localised endpoint url: $apiEndpoint = 'https://accounting.sageone.com.au/api/1.1.1'; $companyId = false; // We don't have this yet $debug = true; $client = new Sage($apiEndpoint, $apiKey, $authCode, $companyId, $debug);
$result = $client->listItems('Company'); if (!empty($result)) { // grab the first Company ID $companyId = $result[0]['ID']; // re-instantiate with $companyId $client = new Sage($apiEndpoint, $apiKey, $authCode, $companyId, $debug); }
// Create a customer $customer_details = [ 'Name' => 'Test Customer', 'Mobile' => '555-555', 'CommunicationMethod' => 0, 'Email' => 'test@test.com', 'PostalAddress01' => '1 test street', 'PostalAddress02' => 'testville', 'PostalAddress03' => 'QLD', 'PostalAddress04' => 4000, 'PostalAddress05' => 'Australia', 'TaxReference' => 'Customer 1', ]; // Save Customer entity $result = $client->saveItem('Customer', $customer_details);