Post

2 followers Follow
0
Avatar

Get all the task & sub-task of all the projects along with comments and discussion using PHP API

Hello Team,

Below is my code to get all the task and subtask of all the projects from my Clarizen. The code is working, however when I crosschecked it is not returning me all the task/sub-task. Morever comments(discussion) are not fetched from this script.

Requirement:

1. Get all the task and subtask of all the projects irrespective of the status.

2. Get the Comments(Discussion) of each of the task if there any.

Please assist me with this on URGENT priority.

============================================================

$request = array();
$params = array(
'userName' => '***',
'password' => '****'
);

$soapUrl = 'https://api.clarizen.com/v1.0/Clarizen.svc?WSDL';
$soapApiUrl = 'http://clarizen.com/api';
$soapConfig = array('exceptions' => 1);


$client = new SoapClient($soapUrl, $soapConfig);
//Login using the credentials above
$response = $client->Login($params);

$sessionId = $response->LoginResult->SessionId;
$userId = $response->LoginResult->UserId;

//Create a SOAP header containing the session ID for future requests
$header = new SoapHeader($soapApiUrl, 'Session', array("ID"=>$sessionId));
$client->__setSoapHeaders($header);

//Create a Query object
$userQuery = new stdClass();
//Set the name of the entity type you are querying
$userQuery->TypeName = 'Task';
//Select the fields you want retrieved from that entity
$userQuery->Fields = array('Name','Project.Name', 'Parent.Name', 'StartDate',
'DueDate', 'Duration', 'State', 'Manager.Email', 'TrackStatus',
'Priority', 'CreatedOn', 'LastUpdatedOn', 'Description',
'ActualEffort', 'RemainingEffort', 'Work');

$request[] = new SoapVar($userQuery, SOAP_ENC_OBJECT, 'EntityQuery', 'http://clarizen.com/api/queries');
//Execute the request
$result = $client->Execute(array("request"=>$request));

//echo "<pre>";print_r($result);echo "</pre>";die();

if($result->ExecuteResult->Result->Success == 1 && $result->ExecuteResult->Result->Error == ''){
$taskArray = array();
foreach($result->ExecuteResult->Result->Entities->BaseEntity as $key => $values){
if(count($values->Values->FieldValue) > 0){
$data = $values->Values->FieldValue;
$temp = array(
'Name' =>$data[0]->Value,
'Project' =>$data[1]->Value->Values->FieldValue->Value,
'Parent' =>$data[2]->Value->Values->FieldValue->Value,
'CreatedOn' => substr($data[10]->Value,0,10),
'LastUpdatedOn' => substr($data[11]->Value,0,10),
'StartDate' => substr($data[3]->Value,0,10),
'DueDate' => substr($data[4]->Value,0,10),
'State' => $data[6]->Value->Id->Value,
'Manager' => $data[7]->Value->Values->FieldValue->Value,
'TrackStatus' => $data[8]->Value->Id->Value,
'Description' => $data[12]->Value,
'ActualEffort' => (3600 * $data[13]->Value->Value),
'RemainingEffort' => (3600 * $data[14]->Value->Value),
'Work' => (3600 * $data[15]->Value->Value)
);
$taskArray[$temp['Project']][]= $temp;
unset($temp);
}

}
echo "<pre>";
print_r($taskArray);
echo "</pre>";
die();
}

=========================================================

Omair Nalkhande Answered

Official comment

Avatar

Hi Omair,

The API uses paging for the results. The default page size is 100, so you were probably getting the first 100 tasks only. You need to use the paging object to specify the starting row, maximum no. of results and if the result has the HasMore property value true, perform the query again with the appropriate values of From & Limit.

I see you're using SOAP API v1.0 with PHP. Looking at your requirements I believe you'll find REST API v2.0 useful (and probably much easier to use with PHP), particularly CZQL query language, that powers you to retrieve entity properties & relations with a single query. Without CZQL you'd have to query the DiscussionLink separately to get the discussions.

A query for tasks and discussion would like that with REST API 2.0 (using curl):

Curl https://api2.clarizen.com/v2.0/services/data/query -X POST -d {"q":"select name,trackstatus,parent, createdon, startdate, duedate, manager,  project.name, (select id,text from discussions) from task"}

Please check the documentation of Clarizen REST API 2.0 & Clarizen CZQL for more information.

Hope this helps,

Ophir

 

Ophir Kenig
Comment actions Permalink

Please sign in to leave a comment.

5 comments

0
Avatar

Hello Ophir,

Thanks for your guidance earlier.

I got the query,

$data = array('q' => "select name, trackstatus, parent.name, createdon, startdate, duedate, manager.email, project.name, (select id,text from discussions) from Task Where project.name = :searchText",

'parameters' => array('searchText' => 'DCWC'),
'paging' => array('from'=> '0', 'limit'=> '100')

);

=========================================================================

Also tried,

$data = array('q' => "select name, trackstatus, parent.name, createdon, startdate, duedate, manager.email, project.name, (select id,text from discussions) from Task Where project.name = 'DCWC'");

in Either above cases i am getting below error.

stdClass Object
(
    [errorCode] => General
    [message] => Invalid Query: Invalid input found: 'project.name' (12:14)
    [referenceId] => ls5cQhnhn8aJhxXMwvNAv
)

Could you please help me here. I want to get all the tasks & sub-task and their discussions of one project.

Awaiting your reply.
Thanks!
Omair

 

Omair Nalkhande 0 votes
Comment actions Permalink
0
Avatar

Hi Omair,

As the documentation suggests, you cannot place conditions on nested fields (i.e. Project.Name) directly; You have to use IN conditions:

IN Subquery conditions can be used to "simulate" conditions on nested fields.
For example, suppose you want to find all the tasks that are in a project with a %completed value greater than 90. One way to present this query is like this:

SELECT Name
FROM Task
/* The following syntax is not correct */
WHERE Project.PercentCompleted > 90

Conditions on nested fields are not valid in CZQL so the above query will fail. However, it can be rewritten using an IN condition and achieve the same results:

SELECT Name
FROM Task
WHERE Project IN (
    SELECT ID 
    FROM project
    WHERE PercentCompleted > 90
)

 

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Hello Ophir,

I have done something like this and it works now.

array('q' => 'SELECT
project.name, name, parent.name, description, createdon, lastupdatedon, startdate, duedate, state.name,
trackstatus.name, manager.email, lastupdatedby.email, work, actualeffort, remainingeffort,
(select id, text, createdon, createdby.email from Discussions)
FROM Task WHERE Project = "/Project/7a636ec4979f4c02807da25a6004b60a"');

However (select id, text, createdon, createdby.email from Discussions) is only providing me the comments of the task and not the replies to the comments.

 

Is there a way i can get both the comments and replies to it along with the task.

DiscussionReply stores the replies.

Thanks

Omair Nalkhande 0 votes
Comment actions Permalink
0
Avatar

Hi Omair,

You'll have to query DiscussionReply separately to retrieve the replies, with a condition on Post  field.

I suggest you add the RepliesCount  field to the sub query on Discussions so you have the ids of the posts that have replies.

By the way, Clarizen allows sharing a view with its relations as a widget which you can embed in your web application, without having to log in to Clarizen. You may find that useful.

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink