The purpose of this package is to facilitate the implementation of our API.
For the complete API documentation and cookbooks please visit our developer website here:
composer require lecompteanytime/api-php-sdk
Follow the examples below to create your client and requests.
Fulfill the parameters below with the connection information supplied by Anytime:
$client = (new ApiClientFactory())->create([
'version' => 'v1.0',
'client-id' => 'YourOAuth2ClientId',
'client-secret' => 'YourOAuth2ClientSecret',
'username' => 'YourOAuth2Username',
'password' => 'YourOAuth2Password',
'private-key' => 'YourPrivateRSAKey'
], Environment::SANDBOX);
Use Environment::PRODUCTION to create a production client.
Before making requests let's take a look to the available APIs:
All these APIs are callable with the api() method like this:
$api = $client->api()->theApiName();
If you don't have yet a valid token, you can create it by calling the "generateToken" method of the client. The token will be initialized directly in the client and returned by the method:
try {
$token = $client->generateToken();
echo $token;
} catch(ApiClientException $e) {
echo 'ERROR: ' . $e->getMessage();
}
If you have already a token, you can just call the method "initToken" of the client:
$client->initToken($yourToken);
We have created several helpers classes to help you to fulfill request params with the correct values. These helpers are classes containing only constants:
The flow is always the same:
All the returned data are available through the response object getters.
To check if all is working fine you can try to call the "GET apicheck" API:
$api = $client->api()->apiCheck();
$request = $api->createRequest();
try {
$response = $api->sendRequest($request);
echo $response->getDateTime()->format('Y-m-d H:i:s');
} catch(ApiClientException $e) {
echo "ERROR: " . $e->getMessage();
}
You can also check post method with the "POST apicheck" API
$api = $client->api()->apiCheckPost();
$request = $api->createRequest()
->setTestParam('This is a test value');
;
try {
$response = $api->sendRequest($request);
echo $response->getTestParam(); // This should print "This is a test value"
} catch(ApiClientException $e) {
echo "ERROR: " . $e->getMessage();
}
$accountListApi = $client->api()->accountList();
$request = $accountListApi->createRequest();
try {
$response = $accountListApi->sendRequest($request);
foreach($response->getAccounts() as $account) {
echo $account->getAccId() . ' - ' . $account->getAccType() . "\n";
}
} catch(ApiClientException $e) {
echo 'ERROR: ' . $e->getMessage();
}