activeCollab SDK
This is a simple PHP library that makes communicating with the activeCollab API much easier. You can find our SDK in this GitHub repository.
First Connection #
In order to connect, you will need the API URL and API token.
To obtain them, visit your User Profile page in activeCollab and select API Subscriptions from the Options drop-down menu. Click on the New Subscription button and fill out the form (the Client Name is the application that will be communicating with activeCollab via the API). After you have created an API subscription for your application, click on the magnifying glass icon to open a dialog that will show you the API URL and token for that subscription.
Now that you have API token and URL, you can test the SDK connection by using this simple example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php require_once 'ActiveCollab/autoload.php'; use \ActiveCollab\Client as API; use \ActiveCollab\Connectors\Curl as CurlConnector; use \ActiveCollab\Exceptions\AppException; API::setUrl('MY-API-URL'); API::setKey('MY-API-TOKEN'); API::setConnector(new CurlConnector); print '<pre>'; print_r(API::info()); print '</pre>';
This example will contact activeCollab and ask for application and user info. Response is a simple associative array with a lot of details about the system that you are communicating with.
Making API Calls #
Listing all tasks in project #65 is easy. Just call:
1
API::call('projects/65/tasks');
This example shows how you can create a new task in the selected project:
1 2 3 4 5 6 7 8 9 10 11 12
try { API::call('projects/65/tasks/add', null, array( 'task[name]' => 'This is a task name', 'task[assignee_id]' => 48, 'task[other_assignees]' => array(3, 1), ), array( '/attach.jpeg' )); } catch(AppException $e) { print $e->getMessage() . '<br><br>'; // var_dump($e->getServerResponse()); (need more info?) } // try
call() method can take four parameters:
- command (required) - API command,
- extra command parameters (optional) - Extra variables that will be attached to the command. Most commands don't require any extra command parameters, but some do (like dont_limit_result param for Tracked time and expenses listing command),
- POST variables - array of POST variables. Note that you do not need to add submitted variable (it is automatically added for you),
- attachments - List of file paths that should be attached to the object that is being created or updated.
For a complete list of available API command, please check the activeCollab API documentation.