Post

2 followers Follow
0
Avatar

Querying a Clarizen Project/Task in PHP

Hello all,

I'm currently trying to get a list of all Clarizen active projects so that I can modify some properties of its tasks. I've read the Clarizen API but it doesn't have many informations on PHP queries. What I managed to do so far is to query all the projects and then test their status one by one. In practice this is not a good approach since I have thousands of projects and not all of them are listed at once. Here's the code:

//LOGIN PROCCESS

$soapUrl = 'https://api.clarizen.com/v1.0/Clarizen.svc?WSDL';
$soapApiUrl = 'http://clarizen.com/api';

$soapConfig = array('exceptions' => 1);
$request = array();
$params = array(
'userName' => $username,
'password' => $password
);

$client = new SoapClient($soapUrl, $soapConfig);
$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 = 'Project';
//Select the fields you want retrieved from that entity
$userQuery->Fields = array('Name', 'State');

/* Doesnt work...*/
/*
$userQuery->Where = new stdClass();
$userQuery->Where->LeftExpression = new stdClass();
$userQuery->Where->LeftExpression->FieldName = 'State';
$userQuery->Where->Operator = 'Equal';
$userQuery->Where->RightExpression = new stdClass();
$userQuery->Where->RightExpression->Value = new stdClass();
$userQuery->Where->RightExpression->Value->TypeName = 'State';
$userQuery->Where->RightExpression->Value->Value = 'Active';
*/
$request[] = new SoapVar($userQuery, SOAP_ENC_OBJECT, 'EntityQuery', 'http://clarizen.com/api/queries');

//Execute the request
$result = $client->Execute(array("request"=>$request));

3 questions follow:

  • What is the right way to query in PHP with the "WHERE" clause
  • How to fetch the tasks of this project and then, for example create a Stopwatch for it.
  • How to continue the query until the hasMore flag is 0, or is there a way to fetch the entire thing all at once?

Thanks in advance.

Import from old forum Answered

Please sign in to leave a comment.

2 comments

0
Avatar

Hi Eytan.

  1. 1. I believe you have to pack the where condition in the correct Soap class i.e.
  • Pack the LeftExpression, Operator and Right Expression in a variable ($Condition)
  • use $UserQuery.Where = new SoapVar ( $Condition,SOAP_ENC_OBJECT, "Compare", "http://clarizen.com/api/queries" )
  1. To query Tasks belonging to a Project, use an EntityQuery on Task (or WorkItem) entity, with a condition on the Project field. The condition may be a simple condition (Equal operator and the EntityId on the Right Expression) or a more complex condition (In operator and a Query expression on the right expression).
  2. To create a stop watch, try creating a StopWatch entity using the Id's of the user and the work item in the corresponding fields.

Hope this helps.

Ophir

Clarizen Team 0 votes
Comment actions Permalink
0
Avatar

Hi there,

I am trying to use the EntityQuery to return the IDs of projects that contain a certain phrase in the name field. Here is the PHP code I am using:

    //Create a Query object

    $userQuery = new stdClass();

    //Set the name of the entity type you are querying

    $userQuery->TypeName = 'Project';

    //Select the fields you want retrieved from that entity

    $userQuery->Fields = array('Name');

    //Pack the LeftExpression, Operator and Right Expression in a variable ($Condition)

    $condition = new stdClass();

    $condition->LeftExpression = new stdClass();

    $condition->LeftExpression->Values = new stdClass();

    $condition->LeftExpression->Values->FieldValue = new stdClass();

    $condition->LeftExpression->Values->FieldValue->FieldName = "Name";

    $condition->Operator = "Contains";

    $condition->RightExpression = new stdClass();

    $condition->RightExpression->Values = new stdClass();

    $condition->RightExpression->Values->FieldValue = new stdClass();

    $condition->RightExpression->Values->FieldValue->FieldName = "Name";

    $condition->RightExpression->Values->FieldValue->Value = "Redesign";

    $userQuery->Where = new SoapVar($condition,SOAP_ENC_OBJECT, "Compare", "http://clarizen.com/api/queries");

    $request[] = new SoapVar($userQuery, SOAP_ENC_OBJECT, 'EntityQuery', 'http://clarizen.com/api/queries');

I am not getting any errors but its returning everything. I don't think my condition/where variables are correct. Please help!

Thanks,

Eddy

Import from old forum 0 votes
Comment actions Permalink