Skip to content
Advertisement

How to Return List of Project Tasks in ActiveCollab

Sorry this may be a trivial question but I am new to PHP. In the documentation to retrieve project tasks, the following code is provided to connect to an Active Collab cloud account:

<?php

require_once '/path/to/vendor/autoload.php';

// Provide name of your company, name of the app that you are developing, your email address and password.
$authenticator = new ActiveCollabSDKAuthenticatorCloud('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember');

// Show all Active Collab 5 and up account that this user has access to.
print_r($authenticator->getAccounts());

// Show user details (first name, last name and avatar URL).
print_r($authenticator->getUser());

// Issue a token for account #123456789.
$token = $authenticator->issueToken(123456789);

// Did we get it?
if ($token instanceof ActiveCollabSDKTokenInterface) {
    print $token->getUrl() . "n";
    print $token->getToken() . "n";
} else {
    print "Invalid responsen";
    die();
}

This works fine. I can then create a client to make API calls:

$client = new ActiveCollabSDKClient($token);

and get the list of tasks for a given project as shown in the documentation.

$client->get('projects/65/tasks'); // PHP object

My question is, what methods/attributes are available to get the list of tasks? I can print the object using print_r() (print will obviously not work), and what I really want is in the raw_response header. This is private however and I cannot access it. How do I actually get the list of tasks (ex: the raw_response either has a string or json object)?

Thanks in advance.

Advertisement

Answer

There are several methods to work with body:

$response = $client->get('projects/65/tasks');

// Will output raw JSON, as string.
$response->getBody();

// Will output parsed JSON, as associative array.
print_r($response->getJson());

For full list of available response methods, please check ResponseInterface.

If you wish to loop through tasks, use something like this:

$response = $client->get('projects/65/tasks');
$parsed_json = $response->getJson();

if (!empty($parsed_json['tasks'])) {
    foreach ($parsed_json['tasks'] as $task) {
        print $task['name'] . "n"
    }
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement